I have this HTML code in a PHP variable that I want to replace:
$text = "<table><tr><td>$something</td></tr><tr>
<td>$var1 $var2</td>
<td>$var3</td>
<td>$var4</td>
</tr><tr><td>$something</td></tr></table>";
I want to replace it with a concatenated HTML code:
$new_text = "<tr>
<td>$new_var1 $new_var2</td>
<td>$new_var3</td>
<td>$new_var4</td>
</tr>
<tr>
<td>$new_var11 $new_var22</td>
<td>$new_var33</td>
<td>$new_var44</td>
</tr>";
I am using str_replace to try to change them but it is not working, I also tried to do rtrim before doing the replace but still to no avail. Will anyone point me to what I am doing wrong here?
What have I tried using str_replace:
$new_text is my concatenated value
$text = str_replace("<tr>
<td>$var1 $var2</td>
<td>$var3</td>
<td>$var4</td>
</tr>", $new_text, $text);
I also tried:
$text = str_replace("<tr>
<td>$var1 $var2</td>
<td>$var3</td>
<td>$var4</td>
</tr>", $new_text, htmlspecialchars($text));
Also:
$text = rtrim($text);
$text = str_replace("<tr>
<td>$var1 $var2</td>
<td>$var3</td>
<td>$var4</td>
</tr>", $new_text, htmlspecialchars($text));
All this are not working.