Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.