PHP - Capitalize the first letter after a dot or after a dot and a space









up vote
2
down vote

favorite












I would like to capitalize the first letter after a dot or after a dot and a space.



$string="I am a string with several periods.period #1. period #2.";


This should be the final string:



I am a string with several periods.Period #1. Period #2.


I have already searched for a solution on stackoverflow but the solution that i found was only for capitalize the initial letter after just a dot and not for a dot and a space.










share|improve this question

















  • 1




    I find the duplicate incorrect. There is nothing in that answer that even mentions the problem OP explains, the optional number of spaces.
    – Andreas
    Nov 10 at 20:48










  • @Andreas, you are right! I have also consulted the link of Wiktor before asking my question.
    – Daniele
    Nov 10 at 20:56














up vote
2
down vote

favorite












I would like to capitalize the first letter after a dot or after a dot and a space.



$string="I am a string with several periods.period #1. period #2.";


This should be the final string:



I am a string with several periods.Period #1. Period #2.


I have already searched for a solution on stackoverflow but the solution that i found was only for capitalize the initial letter after just a dot and not for a dot and a space.










share|improve this question

















  • 1




    I find the duplicate incorrect. There is nothing in that answer that even mentions the problem OP explains, the optional number of spaces.
    – Andreas
    Nov 10 at 20:48










  • @Andreas, you are right! I have also consulted the link of Wiktor before asking my question.
    – Daniele
    Nov 10 at 20:56












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I would like to capitalize the first letter after a dot or after a dot and a space.



$string="I am a string with several periods.period #1. period #2.";


This should be the final string:



I am a string with several periods.Period #1. Period #2.


I have already searched for a solution on stackoverflow but the solution that i found was only for capitalize the initial letter after just a dot and not for a dot and a space.










share|improve this question













I would like to capitalize the first letter after a dot or after a dot and a space.



$string="I am a string with several periods.period #1. period #2.";


This should be the final string:



I am a string with several periods.Period #1. Period #2.


I have already searched for a solution on stackoverflow but the solution that i found was only for capitalize the initial letter after just a dot and not for a dot and a space.







php regex string function text






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 16:35









Daniele

647




647







  • 1




    I find the duplicate incorrect. There is nothing in that answer that even mentions the problem OP explains, the optional number of spaces.
    – Andreas
    Nov 10 at 20:48










  • @Andreas, you are right! I have also consulted the link of Wiktor before asking my question.
    – Daniele
    Nov 10 at 20:56












  • 1




    I find the duplicate incorrect. There is nothing in that answer that even mentions the problem OP explains, the optional number of spaces.
    – Andreas
    Nov 10 at 20:48










  • @Andreas, you are right! I have also consulted the link of Wiktor before asking my question.
    – Daniele
    Nov 10 at 20:56







1




1




I find the duplicate incorrect. There is nothing in that answer that even mentions the problem OP explains, the optional number of spaces.
– Andreas
Nov 10 at 20:48




I find the duplicate incorrect. There is nothing in that answer that even mentions the problem OP explains, the optional number of spaces.
– Andreas
Nov 10 at 20:48












@Andreas, you are right! I have also consulted the link of Wiktor before asking my question.
– Daniele
Nov 10 at 20:56




@Andreas, you are right! I have also consulted the link of Wiktor before asking my question.
– Daniele
Nov 10 at 20:56












4 Answers
4






active

oldest

votes

















up vote
0
down vote



accepted










Use regex to match the dot ., optional space s* and a letter w.

Then loop the matches array and do a str_replace.



$str="I am a string with several periods.period #1. period #2.";
preg_match_all("/.s*w/", $str, $matches);

foreach($matches[0] as $match)
$str = str_replace($match, strtoupper($match), $str);

echo $str;
//I am a string with several periods.Period #1. Period #2.


https://3v4l.org/LevU5



To make it slightly more optimized you could add an array_unique before looping since str_replace replaces all equal substrings.



$matches[0] = array_unique($matches[0]);


https://3v4l.org/mIiX8






share|improve this answer






















  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • @Toto I can bet my left arm that it's the person who had his duplicate hammer removed from this question.
    – Andreas
    Nov 12 at 21:13

















up vote
1
down vote













Preg_replace_callback is your friend:



$string="I am a string with several periods.period #1. period #2.";
$string = preg_replace_callback('/.s*Kw/',
function($m)
return strtoupper($m[0]);
,
$string);
echo $string;


Output:



I am a string with several periods.Period #1. Period #2.





share|improve this answer
















  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • What's going on with all the downvotes to all the answers?
    – Sherif Salah
    Nov 12 at 19:57

















up vote
0
down vote













If regex is not an option, something like this might work:



$str = "I am a string with several periods.period #1. period #2.";
$strings = explode('.', $str);
$titleCased = ;

foreach($strings as $s)
$titleCased = ucfirst(trim($s));

echo join(".", $titleCased);


Although, this has the added effect of removing whitespace.



https://3v4l.org/fWGUW






share|improve this answer






















  • the white space should remain
    – Daniele
    Nov 10 at 16:59










  • You could just join with ". " and that would make it "correct" as well. Although that may not be what OP wants though.
    – Andreas
    Nov 10 at 17:02










  • @Daniele if you remove trim you get the expected result with this code. Edit, sorry no you don't. My mistake
    – Andreas
    Nov 10 at 17:05











  • But this will work. 3v4l.org/RWnfv @erickb feel free to add this to your answer if you want
    – Andreas
    Nov 10 at 17:10











  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28

















up vote
0
down vote













I created this simple function and it works like a charm



and you can add delimiters as you like.



function capitalize_after_delimiters($string='', $delimiters = array())

foreach ($delimiters as $delimiter)

$temp = explode($delimiter, $string);
array_walk($temp, function (&$value) $value = ucfirst($value); );
$string = implode($temp, $delimiter);

return $string;


$string ="I am a string with several periods.period #1. period #2.";

$result = capitalize_after_delimiters($string, array('.', '. '));

var_dump($result);

result: string(56) "I am a string with several periods.Period #1. Period #2."


result






share|improve this answer






















  • excellent solution!
    – Daniele
    Nov 10 at 18:42










  • This solution is good but can fail in many ways. If the text has three spaces it fails (or you have to manually add it), if there is a new line after the dot it fails. 3v4l.org/lcBZG
    – Andreas
    Nov 10 at 19:55










  • I solved his problem as he asked and add some extra features too, but if you want to make it absolutely perfect solution in general, then we can work on that.
    – Sherif Salah
    Nov 10 at 20:07










  • your proposed problem solved 3v4l.org/QepCm
    – Sherif Salah
    Nov 10 at 20:19







  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241052%2fphp-capitalize-the-first-letter-after-a-dot-or-after-a-dot-and-a-space%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










Use regex to match the dot ., optional space s* and a letter w.

Then loop the matches array and do a str_replace.



$str="I am a string with several periods.period #1. period #2.";
preg_match_all("/.s*w/", $str, $matches);

foreach($matches[0] as $match)
$str = str_replace($match, strtoupper($match), $str);

echo $str;
//I am a string with several periods.Period #1. Period #2.


https://3v4l.org/LevU5



To make it slightly more optimized you could add an array_unique before looping since str_replace replaces all equal substrings.



$matches[0] = array_unique($matches[0]);


https://3v4l.org/mIiX8






share|improve this answer






















  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • @Toto I can bet my left arm that it's the person who had his duplicate hammer removed from this question.
    – Andreas
    Nov 12 at 21:13














up vote
0
down vote



accepted










Use regex to match the dot ., optional space s* and a letter w.

Then loop the matches array and do a str_replace.



$str="I am a string with several periods.period #1. period #2.";
preg_match_all("/.s*w/", $str, $matches);

foreach($matches[0] as $match)
$str = str_replace($match, strtoupper($match), $str);

echo $str;
//I am a string with several periods.Period #1. Period #2.


https://3v4l.org/LevU5



To make it slightly more optimized you could add an array_unique before looping since str_replace replaces all equal substrings.



$matches[0] = array_unique($matches[0]);


https://3v4l.org/mIiX8






share|improve this answer






















  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • @Toto I can bet my left arm that it's the person who had his duplicate hammer removed from this question.
    – Andreas
    Nov 12 at 21:13












up vote
0
down vote



accepted







up vote
0
down vote



accepted






Use regex to match the dot ., optional space s* and a letter w.

Then loop the matches array and do a str_replace.



$str="I am a string with several periods.period #1. period #2.";
preg_match_all("/.s*w/", $str, $matches);

foreach($matches[0] as $match)
$str = str_replace($match, strtoupper($match), $str);

echo $str;
//I am a string with several periods.Period #1. Period #2.


https://3v4l.org/LevU5



To make it slightly more optimized you could add an array_unique before looping since str_replace replaces all equal substrings.



$matches[0] = array_unique($matches[0]);


https://3v4l.org/mIiX8






share|improve this answer














Use regex to match the dot ., optional space s* and a letter w.

Then loop the matches array and do a str_replace.



$str="I am a string with several periods.period #1. period #2.";
preg_match_all("/.s*w/", $str, $matches);

foreach($matches[0] as $match)
$str = str_replace($match, strtoupper($match), $str);

echo $str;
//I am a string with several periods.Period #1. Period #2.


https://3v4l.org/LevU5



To make it slightly more optimized you could add an array_unique before looping since str_replace replaces all equal substrings.



$matches[0] = array_unique($matches[0]);


https://3v4l.org/mIiX8







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 16:48

























answered Nov 10 at 16:43









Andreas

14.6k31441




14.6k31441











  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • @Toto I can bet my left arm that it's the person who had his duplicate hammer removed from this question.
    – Andreas
    Nov 12 at 21:13
















  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • @Toto I can bet my left arm that it's the person who had his duplicate hammer removed from this question.
    – Andreas
    Nov 12 at 21:13















Serial downvoter in action, all answers has been downvoted at 18h05 UTC
– Toto
Nov 12 at 19:28




Serial downvoter in action, all answers has been downvoted at 18h05 UTC
– Toto
Nov 12 at 19:28












@Toto I can bet my left arm that it's the person who had his duplicate hammer removed from this question.
– Andreas
Nov 12 at 21:13




@Toto I can bet my left arm that it's the person who had his duplicate hammer removed from this question.
– Andreas
Nov 12 at 21:13












up vote
1
down vote













Preg_replace_callback is your friend:



$string="I am a string with several periods.period #1. period #2.";
$string = preg_replace_callback('/.s*Kw/',
function($m)
return strtoupper($m[0]);
,
$string);
echo $string;


Output:



I am a string with several periods.Period #1. Period #2.





share|improve this answer
















  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • What's going on with all the downvotes to all the answers?
    – Sherif Salah
    Nov 12 at 19:57














up vote
1
down vote













Preg_replace_callback is your friend:



$string="I am a string with several periods.period #1. period #2.";
$string = preg_replace_callback('/.s*Kw/',
function($m)
return strtoupper($m[0]);
,
$string);
echo $string;


Output:



I am a string with several periods.Period #1. Period #2.





share|improve this answer
















  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • What's going on with all the downvotes to all the answers?
    – Sherif Salah
    Nov 12 at 19:57












up vote
1
down vote










up vote
1
down vote









Preg_replace_callback is your friend:



$string="I am a string with several periods.period #1. period #2.";
$string = preg_replace_callback('/.s*Kw/',
function($m)
return strtoupper($m[0]);
,
$string);
echo $string;


Output:



I am a string with several periods.Period #1. Period #2.





share|improve this answer












Preg_replace_callback is your friend:



$string="I am a string with several periods.period #1. period #2.";
$string = preg_replace_callback('/.s*Kw/',
function($m)
return strtoupper($m[0]);
,
$string);
echo $string;


Output:



I am a string with several periods.Period #1. Period #2.






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 17:07









Toto

64k175697




64k175697







  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • What's going on with all the downvotes to all the answers?
    – Sherif Salah
    Nov 12 at 19:57












  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28










  • What's going on with all the downvotes to all the answers?
    – Sherif Salah
    Nov 12 at 19:57







1




1




Serial downvoter in action, all answers has been downvoted at 18h05 UTC
– Toto
Nov 12 at 19:28




Serial downvoter in action, all answers has been downvoted at 18h05 UTC
– Toto
Nov 12 at 19:28












What's going on with all the downvotes to all the answers?
– Sherif Salah
Nov 12 at 19:57




What's going on with all the downvotes to all the answers?
– Sherif Salah
Nov 12 at 19:57










up vote
0
down vote













If regex is not an option, something like this might work:



$str = "I am a string with several periods.period #1. period #2.";
$strings = explode('.', $str);
$titleCased = ;

foreach($strings as $s)
$titleCased = ucfirst(trim($s));

echo join(".", $titleCased);


Although, this has the added effect of removing whitespace.



https://3v4l.org/fWGUW






share|improve this answer






















  • the white space should remain
    – Daniele
    Nov 10 at 16:59










  • You could just join with ". " and that would make it "correct" as well. Although that may not be what OP wants though.
    – Andreas
    Nov 10 at 17:02










  • @Daniele if you remove trim you get the expected result with this code. Edit, sorry no you don't. My mistake
    – Andreas
    Nov 10 at 17:05











  • But this will work. 3v4l.org/RWnfv @erickb feel free to add this to your answer if you want
    – Andreas
    Nov 10 at 17:10











  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28














up vote
0
down vote













If regex is not an option, something like this might work:



$str = "I am a string with several periods.period #1. period #2.";
$strings = explode('.', $str);
$titleCased = ;

foreach($strings as $s)
$titleCased = ucfirst(trim($s));

echo join(".", $titleCased);


Although, this has the added effect of removing whitespace.



https://3v4l.org/fWGUW






share|improve this answer






















  • the white space should remain
    – Daniele
    Nov 10 at 16:59










  • You could just join with ". " and that would make it "correct" as well. Although that may not be what OP wants though.
    – Andreas
    Nov 10 at 17:02










  • @Daniele if you remove trim you get the expected result with this code. Edit, sorry no you don't. My mistake
    – Andreas
    Nov 10 at 17:05











  • But this will work. 3v4l.org/RWnfv @erickb feel free to add this to your answer if you want
    – Andreas
    Nov 10 at 17:10











  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28












up vote
0
down vote










up vote
0
down vote









If regex is not an option, something like this might work:



$str = "I am a string with several periods.period #1. period #2.";
$strings = explode('.', $str);
$titleCased = ;

foreach($strings as $s)
$titleCased = ucfirst(trim($s));

echo join(".", $titleCased);


Although, this has the added effect of removing whitespace.



https://3v4l.org/fWGUW






share|improve this answer














If regex is not an option, something like this might work:



$str = "I am a string with several periods.period #1. period #2.";
$strings = explode('.', $str);
$titleCased = ;

foreach($strings as $s)
$titleCased = ucfirst(trim($s));

echo join(".", $titleCased);


Although, this has the added effect of removing whitespace.



https://3v4l.org/fWGUW







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 17:17









Martin

12.2k53377




12.2k53377










answered Nov 10 at 16:58









erickb

4,55121919




4,55121919











  • the white space should remain
    – Daniele
    Nov 10 at 16:59










  • You could just join with ". " and that would make it "correct" as well. Although that may not be what OP wants though.
    – Andreas
    Nov 10 at 17:02










  • @Daniele if you remove trim you get the expected result with this code. Edit, sorry no you don't. My mistake
    – Andreas
    Nov 10 at 17:05











  • But this will work. 3v4l.org/RWnfv @erickb feel free to add this to your answer if you want
    – Andreas
    Nov 10 at 17:10











  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28
















  • the white space should remain
    – Daniele
    Nov 10 at 16:59










  • You could just join with ". " and that would make it "correct" as well. Although that may not be what OP wants though.
    – Andreas
    Nov 10 at 17:02










  • @Daniele if you remove trim you get the expected result with this code. Edit, sorry no you don't. My mistake
    – Andreas
    Nov 10 at 17:05











  • But this will work. 3v4l.org/RWnfv @erickb feel free to add this to your answer if you want
    – Andreas
    Nov 10 at 17:10











  • Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28















the white space should remain
– Daniele
Nov 10 at 16:59




the white space should remain
– Daniele
Nov 10 at 16:59












You could just join with ". " and that would make it "correct" as well. Although that may not be what OP wants though.
– Andreas
Nov 10 at 17:02




You could just join with ". " and that would make it "correct" as well. Although that may not be what OP wants though.
– Andreas
Nov 10 at 17:02












@Daniele if you remove trim you get the expected result with this code. Edit, sorry no you don't. My mistake
– Andreas
Nov 10 at 17:05





@Daniele if you remove trim you get the expected result with this code. Edit, sorry no you don't. My mistake
– Andreas
Nov 10 at 17:05













But this will work. 3v4l.org/RWnfv @erickb feel free to add this to your answer if you want
– Andreas
Nov 10 at 17:10





But this will work. 3v4l.org/RWnfv @erickb feel free to add this to your answer if you want
– Andreas
Nov 10 at 17:10













Serial downvoter in action, all answers has been downvoted at 18h05 UTC
– Toto
Nov 12 at 19:28




Serial downvoter in action, all answers has been downvoted at 18h05 UTC
– Toto
Nov 12 at 19:28










up vote
0
down vote













I created this simple function and it works like a charm



and you can add delimiters as you like.



function capitalize_after_delimiters($string='', $delimiters = array())

foreach ($delimiters as $delimiter)

$temp = explode($delimiter, $string);
array_walk($temp, function (&$value) $value = ucfirst($value); );
$string = implode($temp, $delimiter);

return $string;


$string ="I am a string with several periods.period #1. period #2.";

$result = capitalize_after_delimiters($string, array('.', '. '));

var_dump($result);

result: string(56) "I am a string with several periods.Period #1. Period #2."


result






share|improve this answer






















  • excellent solution!
    – Daniele
    Nov 10 at 18:42










  • This solution is good but can fail in many ways. If the text has three spaces it fails (or you have to manually add it), if there is a new line after the dot it fails. 3v4l.org/lcBZG
    – Andreas
    Nov 10 at 19:55










  • I solved his problem as he asked and add some extra features too, but if you want to make it absolutely perfect solution in general, then we can work on that.
    – Sherif Salah
    Nov 10 at 20:07










  • your proposed problem solved 3v4l.org/QepCm
    – Sherif Salah
    Nov 10 at 20:19







  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28














up vote
0
down vote













I created this simple function and it works like a charm



and you can add delimiters as you like.



function capitalize_after_delimiters($string='', $delimiters = array())

foreach ($delimiters as $delimiter)

$temp = explode($delimiter, $string);
array_walk($temp, function (&$value) $value = ucfirst($value); );
$string = implode($temp, $delimiter);

return $string;


$string ="I am a string with several periods.period #1. period #2.";

$result = capitalize_after_delimiters($string, array('.', '. '));

var_dump($result);

result: string(56) "I am a string with several periods.Period #1. Period #2."


result






share|improve this answer






















  • excellent solution!
    – Daniele
    Nov 10 at 18:42










  • This solution is good but can fail in many ways. If the text has three spaces it fails (or you have to manually add it), if there is a new line after the dot it fails. 3v4l.org/lcBZG
    – Andreas
    Nov 10 at 19:55










  • I solved his problem as he asked and add some extra features too, but if you want to make it absolutely perfect solution in general, then we can work on that.
    – Sherif Salah
    Nov 10 at 20:07










  • your proposed problem solved 3v4l.org/QepCm
    – Sherif Salah
    Nov 10 at 20:19







  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28












up vote
0
down vote










up vote
0
down vote









I created this simple function and it works like a charm



and you can add delimiters as you like.



function capitalize_after_delimiters($string='', $delimiters = array())

foreach ($delimiters as $delimiter)

$temp = explode($delimiter, $string);
array_walk($temp, function (&$value) $value = ucfirst($value); );
$string = implode($temp, $delimiter);

return $string;


$string ="I am a string with several periods.period #1. period #2.";

$result = capitalize_after_delimiters($string, array('.', '. '));

var_dump($result);

result: string(56) "I am a string with several periods.Period #1. Period #2."


result






share|improve this answer














I created this simple function and it works like a charm



and you can add delimiters as you like.



function capitalize_after_delimiters($string='', $delimiters = array())

foreach ($delimiters as $delimiter)

$temp = explode($delimiter, $string);
array_walk($temp, function (&$value) $value = ucfirst($value); );
$string = implode($temp, $delimiter);

return $string;


$string ="I am a string with several periods.period #1. period #2.";

$result = capitalize_after_delimiters($string, array('.', '. '));

var_dump($result);

result: string(56) "I am a string with several periods.Period #1. Period #2."


result







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 19:37









Andreas

14.6k31441




14.6k31441










answered Nov 10 at 17:43









Sherif Salah

37327




37327











  • excellent solution!
    – Daniele
    Nov 10 at 18:42










  • This solution is good but can fail in many ways. If the text has three spaces it fails (or you have to manually add it), if there is a new line after the dot it fails. 3v4l.org/lcBZG
    – Andreas
    Nov 10 at 19:55










  • I solved his problem as he asked and add some extra features too, but if you want to make it absolutely perfect solution in general, then we can work on that.
    – Sherif Salah
    Nov 10 at 20:07










  • your proposed problem solved 3v4l.org/QepCm
    – Sherif Salah
    Nov 10 at 20:19







  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28
















  • excellent solution!
    – Daniele
    Nov 10 at 18:42










  • This solution is good but can fail in many ways. If the text has three spaces it fails (or you have to manually add it), if there is a new line after the dot it fails. 3v4l.org/lcBZG
    – Andreas
    Nov 10 at 19:55










  • I solved his problem as he asked and add some extra features too, but if you want to make it absolutely perfect solution in general, then we can work on that.
    – Sherif Salah
    Nov 10 at 20:07










  • your proposed problem solved 3v4l.org/QepCm
    – Sherif Salah
    Nov 10 at 20:19







  • 1




    Serial downvoter in action, all answers has been downvoted at 18h05 UTC
    – Toto
    Nov 12 at 19:28















excellent solution!
– Daniele
Nov 10 at 18:42




excellent solution!
– Daniele
Nov 10 at 18:42












This solution is good but can fail in many ways. If the text has three spaces it fails (or you have to manually add it), if there is a new line after the dot it fails. 3v4l.org/lcBZG
– Andreas
Nov 10 at 19:55




This solution is good but can fail in many ways. If the text has three spaces it fails (or you have to manually add it), if there is a new line after the dot it fails. 3v4l.org/lcBZG
– Andreas
Nov 10 at 19:55












I solved his problem as he asked and add some extra features too, but if you want to make it absolutely perfect solution in general, then we can work on that.
– Sherif Salah
Nov 10 at 20:07




I solved his problem as he asked and add some extra features too, but if you want to make it absolutely perfect solution in general, then we can work on that.
– Sherif Salah
Nov 10 at 20:07












your proposed problem solved 3v4l.org/QepCm
– Sherif Salah
Nov 10 at 20:19





your proposed problem solved 3v4l.org/QepCm
– Sherif Salah
Nov 10 at 20:19





1




1




Serial downvoter in action, all answers has been downvoted at 18h05 UTC
– Toto
Nov 12 at 19:28




Serial downvoter in action, all answers has been downvoted at 18h05 UTC
– Toto
Nov 12 at 19:28

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241052%2fphp-capitalize-the-first-letter-after-a-dot-or-after-a-dot-and-a-space%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto