How can I replace words in string and ignore already replaced ones?
$about_me ="this is a how to make money make money money test";
$money_array1 = "how to make money
how to make cash
how to earn cash
how to earn money";
$money_array2 = "make money
make cash
earn cash
earn money";
$money_array3 = "money
cash";
$money_array1 = explode("\r\n", $money_array1);
$money_array2 = explode("\r\n", $money_array2);
$money_array3 = explode("\r\n", $money_array3);
I can’t see from the code exactly what it is you are trying to achieve, can you give a more detailed explanation perhaps with some examples?
In the past, if I’ve used a string-search to search for a word, and then replaced it using string manipulation, I simply do the next string-search starting from after the previous one.
Thanks buddy for your replay. I mean that if you have “how to make money” in the string it will replace this and then “make money” and “money” so it will be a mess.
I need some how once you replace one word stop grabbing words from it to try to match other words.
$about_me ="this is a how to make money make money money test";
$money_array1 = "how to make money
how to make cash
how to earn cash
how to earn money";
$money_array2 = "make money
make cash
earn cash
earn money";
$money_array3 = "money
cash";
$money_array1 = explode("\r\n", $money_array1);
$money_array2 = explode("\r\n", $money_array2);
$money_array3 = explode("\r\n", $money_array3);
foreach($money_array1 as $vall)
{
$pattern = '/\b('.$vall.')\b/i';
$about_me = preg_replace($pattern, "<a href=\"/link_h\">".$vall."</a>", $about_me);
}
foreach($money_array2 as $vall)
{
$pattern = '/\b('.$vall.')\b/i';
$about_me = preg_replace($pattern, "<a href=\"/link_h\">".$vall."</a>", $about_me);
}
foreach($money_array3 as $vall)
{
$pattern = '/\b('.$vall.')\b/i';
$about_me = preg_replace($pattern, "<a href=\"/link_h\">".$vall."</a>", $about_me);
}
I have no idea what you’re on about. Can you give an example of a supplied input and an expected output? No code, just a string that goes in, and what sting comes out.