The Little Guy Posted October 5, 2007 Share Posted October 5, 2007 OK, I can not get this... I need to upper case the first letter in $str, but my word boundary is getting the single quote as part of the word boundary, along with bout. I want to just uppercase the b in the following code. Note: The word to be upper case will not always be b Here is the code: <?php $str = "how 'bout it?"; preg_replace("~'\b[a-z]{3,}\s~e","ucfirst('$0')",$str); ?> Link to comment https://forums.phpfreaks.com/topic/71912-upper-case-a-letter-after-a-quote/ Share on other sites More sharing options...
darkfreaks Posted October 5, 2007 Share Posted October 5, 2007 <?php $value= strpos('b',$str); if (!$value) { echo " could not return the function"; } else { strtoupper ($value); }?> Link to comment https://forums.phpfreaks.com/topic/71912-upper-case-a-letter-after-a-quote/#findComment-362251 Share on other sites More sharing options...
heckenschutze Posted October 5, 2007 Share Posted October 5, 2007 Use strpos, or a simpler regex, there won't always be a space after 'bout ie: "that's all it's 'about". You'll want to match, [space][single apostrophe][a-z] Link to comment https://forums.phpfreaks.com/topic/71912-upper-case-a-letter-after-a-quote/#findComment-362252 Share on other sites More sharing options...
The Little Guy Posted October 5, 2007 Author Share Posted October 5, 2007 Use strpos, or a simpler regex, there won't always be a space after 'bout ie: "that's all it's 'about". You'll want to match, [space][single apostrophe][a-z] I don't always want to match [space][single apostrophe][a-z] because sometimes its a the beginning of a sentence ie: "'bout it" : http://viplyrics.com/artist/Young%20Joc/Unknown/'bout%20It and sometimes I have a word like this: A'alnadda In that case, I don't want the second "a" uppercase. Here are all my current rules: <?php function editTxt($str){ $nedit = strtolower($str); $find = array( "~\s'\b[a-z]\s~e", "~&~", "~\s\s+~", "~^(a|an|the)\s+(.+)~i"); $replace = array( "strtoupper('$0')", "and", " ", "$2, $1"); return preg_replace($find,$replace,$nedit); } Link to comment https://forums.phpfreaks.com/topic/71912-upper-case-a-letter-after-a-quote/#findComment-362637 Share on other sites More sharing options...
GingerRobot Posted October 5, 2007 Share Posted October 5, 2007 Hmm, just a thought...couldn't you explode by the space, then deal with each word individually? If the first character of the word is an apostrophe, you'll want to make the next character uppercase? <?php $str = "how 'bout it?"; $words = explode(' ',$str); foreach($words as $k =>$v){ if($v[0]== "'"){ $words[$k][1] = strtoupper($v[1]); } } $str = implode(' ',$words); echo $str; ?> Link to comment https://forums.phpfreaks.com/topic/71912-upper-case-a-letter-after-a-quote/#findComment-362644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.