Jump to content

preg_match & sending non matched words to a function. help.


jamesxg1

Recommended Posts

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.

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.