jamesxg1 Posted March 26, 2010 Share Posted March 26, 2010 Hiya peeps, This is something very complicated and I'm in need of some help I need to do the following. EXAMPLE TEXT = 'hiya, Bye for now'; How do I do the following? 1) Add a ' . ' dot at the end, remove any space from the end. 2) recognise the comma and change 'Bye for now' into 'bye for now'. Many thanks James. Link to comment https://forums.phpfreaks.com/topic/196617-character-match-text-change-and-space-removal-help/ Share on other sites More sharing options...
jamesxg1 Posted March 26, 2010 Author Share Posted March 26, 2010 Sorry for another post, basically I'm trying to grammatically fix a string of text. Many thanks James. Link to comment https://forums.phpfreaks.com/topic/196617-character-match-text-change-and-space-removal-help/#findComment-1032314 Share on other sites More sharing options...
mattal999 Posted March 26, 2010 Share Posted March 26, 2010 This should get you on your way: $string = "hiya, Bye for now"; $string = ucfirst(strtolower($string)); // Make it all lowercase then format the first word uppercase. $string = trim($string); // Remove whitespace. if(substr($string, -1) !== ".") $string .= "."; // Add a full stop if it doesn't already have one. echo $string; // Should produce: Hiya, bye for now. Link to comment https://forums.phpfreaks.com/topic/196617-character-match-text-change-and-space-removal-help/#findComment-1032325 Share on other sites More sharing options...
teamatomic Posted March 26, 2010 Share Posted March 26, 2010 $str=str_replace(",","",$str); //replace comma with nothing HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/196617-character-match-text-change-and-space-removal-help/#findComment-1032326 Share on other sites More sharing options...
jamesxg1 Posted March 26, 2010 Author Share Posted March 26, 2010 Thats stunning thanks guys, I've got another lil issue so to save opening another thread, I will post here. $input= 'hiya, how are you?'; $match = array('how are you'); $output = array(); foreach($match as $sentence_split): $sentence_split_slash = '/' . $sentence_split . '/'; if(preg_match($sentence_split_slash, $input)): $output[] = $sentence_split; else: $this->conversate_word($sentence_split); endif; endforeach; how do I make it so that the 'hiya' is actually sent to $this->conversate_word(); Many thanks James. Link to comment https://forums.phpfreaks.com/topic/196617-character-match-text-change-and-space-removal-help/#findComment-1032360 Share on other sites More sharing options...
jamesxg1 Posted March 26, 2010 Author Share Posted March 26, 2010 BUMP. Link to comment https://forums.phpfreaks.com/topic/196617-character-match-text-change-and-space-removal-help/#findComment-1032383 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.