Jump to content

Write out mach?


kla0005

Recommended Posts

Hello goys,

if i have this variable:

 

$words = "my,dog,year";

 

And i have an another variable:

 

$string = "Hello, My name is Inge, and i am 1010 years old. My dog is very sweet, so are my brothers dogs.";

 

- How can i make a system that tjek for each word after matches in the string?

so it writes the matches, as 'Match: Dog', and 'Match: year' .. But also make it tjek after matches that dosent mach 100%, as i just dont get 'dog', i get'Match: Dog' and: Match: dogs' ?

 

Someone who can help me, thanks :)

Link to comment
https://forums.phpfreaks.com/topic/191642-write-out-mach/
Share on other sites

What u need is thing called RegExp

I am not uber good at it but something like this should work

$result = preg_replace('/(my|dog|years)/sim', 'Match:\\1', $string);

and as u can see words that u are interested must be seperated by |

so if u get words list from somewhere allredy joined with , u then should do something like

$words = explode(',', "my,dog,years");
$result = preg_replace('/('.implode('|', $words).')/sim', 'Match:\\1', $string);

Link to comment
https://forums.phpfreaks.com/topic/191642-write-out-mach/#findComment-1010177
Share on other sites

$words = "my,dog,year";
$string = "Hello, My name is Inge, and i am 1010 years old. My dog is very sweet, so are my brothers dogs.";

foreach(explode(',', $words) as $word)
  if(stripos($string, $word))
    echo 'Match: ',$word,'<br/>';

 

«Dogs» probably need an external dictionary.

Link to comment
https://forums.phpfreaks.com/topic/191642-write-out-mach/#findComment-1010182
Share on other sites

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.