jamesxg1 Posted March 26, 2010 Share Posted March 26, 2010 Hiya peeps! $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/196635-preg_match-sending-non-matched-words-to-a-function-help/ Share on other sites More sharing options...
MatthewJ Posted March 26, 2010 Share Posted March 26, 2010 $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; //Replace array $replace = array(',', '?', $sentence_split); $conv_word = trim(str_replace($replace, "", $input)); $this->conversate_word($conv_word); } } I just assumed you would want the , and the ? to be removed as well so I added those into the replace array. Link to comment https://forums.phpfreaks.com/topic/196635-preg_match-sending-non-matched-words-to-a-function-help/#findComment-1032443 Share on other sites More sharing options...
jamesxg1 Posted March 26, 2010 Author Share Posted March 26, 2010 Hiya bud, Cheers for the reply, I already strip the text of special characters, but cheers for the help bud, and it didnt work unfortunatly :S. Many thanks James. Link to comment https://forums.phpfreaks.com/topic/196635-preg_match-sending-non-matched-words-to-a-function-help/#findComment-1032518 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/196635-preg_match-sending-non-matched-words-to-a-function-help/#findComment-1032526 Share on other sites More sharing options...
MatthewJ Posted March 27, 2010 Share Posted March 27, 2010 Hmmm... if I replace $this->conversate_word($conv_word); with echo $conv_word; the result is "hiya" so it is being passed to the conversate_word method... what isn't working? Link to comment https://forums.phpfreaks.com/topic/196635-preg_match-sending-non-matched-words-to-a-function-help/#findComment-1032635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.