June 11, 200818 yr Is there a variation of ucfirst () which will convert to sentince form - ie Capitalises after every full stop (.) but leaves already existing words capitalised? so hi I am enjoying the Webdesigners forum. it's really cool. would change to: Hi I am enjoying the Webdesigners forum. It's really cool.
June 24, 200818 yr Is there a variation of ucfirst () which will convert to sentince form - ie Capitalises after every full stop (.) but leaves already existing words capitalised? so hi I am enjoying the Webdesigners forum. it's really cool. would change to: Hi I am enjoying the Webdesigners forum. It's really cool. You would need to use explode() with full stops. I've had a quick look on the PHP site and found this posting... <?php $text="this is a sentence. this is another sentence."; $split=explode(". ", $text); foreach ($split as $sentence) { $sentencegood=ucfirst($sentence); $text=str_replace($sentence, $sentencegood, $text); } echo $text; // This is a sentence. This is another sentence. ?> Not tested it, but looks like it should work. Good luck!
June 24, 200818 yr Nice one Paul .. I took a shot at the code too ... here's my solution (with comments too): //you should explode the dot only with no spaces //you could also transform the text to lowercase (just in case you have "tHiS is a seTence.this is another.") $split = explode(".", strtolower($text)); foreach ($split as $sentence) { //here I'm building an array with sentences, uppercasing the first letter and removing unnecessary left/right spaces $sentence2[] = ucfirst(trim($sentence)); } //you can implode the array with the dot+space and also remove the last space $text = rtrim(implode(". ",$sentence2)); echo $text; //This is a sentence. This is another sentence. PHP is fun
Create an account or sign in to comment