I'm trying to find & replace my values from inside string after getting values from inside loop. When I replace my string from inside loop then(that method isn't suitable)as it replaces one by one until loop ends and I get a lot of strings with single replacements at each. I'm trying to replace the whole string with loop values outside only once. Here's my code.
$str = "wi are checking it";
$langs = array ('w', 'c', 'i');
foreach ($langs as $lang) {
$search = $lang;
$url[] = "<span style='color:red;'>".$search."</span>";
$qw[] = $search;
}
$op = implode("", $url);
$er = implode("", $qw);
echo $op."<br>";
echo $er."<br>";
$new = str_replace($er, $op, $str);
echo $new;
It's output:
Expected Output:
[

$search = $lang;Why, what does that achieve?$qw[] = $search;in the loop? So the$qwwill now look EXACTLY like the$langsarray ???