php - How to seperate a sentence like this -


how separate sentence "comma" , @ last using "and " in php like

"bruce_campbell actor , director , creator , producer , musician."?

now want to show the sentence this...

""bruce_campbell actor , director ,creator , producer , musician.""

you don't want replace last , in string.

$str = "bruce_campbell actor , director , creator , producer , musician.\n"; $except_last_and = substr_count($str, 'and') - 1; $resstr = preg_replace("/and/", ' , ', $str, $except_last_and); echo $resstr; 

but gautam3164 correct should google first.

and php manual great resource.

http://ca1.php.net/preg_replace

http://www.php.net/manual/en/function.substr-count.php


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -