soma56 Posted May 15, 2012 Share Posted May 15, 2012 From what I understand we can use ucfirst to convert the first letter within a string to upper case. What I would like to know is if there is a function that exists that would convert the first letter of every paragraph to upper case. For example: From: This is a paragraph. is this the car blue? let's go for a pint of beer! To: This is a paragraph. Is this the car blue? Let's go for a pint of beer! Does any such function exist? Link to comment https://forums.phpfreaks.com/topic/262566-convert-the-first-letter-of-every-paragraph-to-upper-case/ Share on other sites More sharing options...
QuickOldCar Posted May 15, 2012 Share Posted May 15, 2012 <?php function upperFirstWord($str) { return preg_replace('/([.!?])\s*(\w)/e', "strtoupper('\\1 \\2')", ucfirst(strtolower($str))); } echo upperFirstWord("This is a paragraph. is this the car blue? let's go for a pint of beer!"); ?> Link to comment https://forums.phpfreaks.com/topic/262566-convert-the-first-letter-of-every-paragraph-to-upper-case/#findComment-1345658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.