Skip to content
Advertisement

PHP str_replace notworking if used 2 times

So I have this practical page I made to see if I can make a template language, the code is listed below:

JavaScript

It seems like if I add 2 str_replace functions, the echo is blank, and the $e var is working fine.

I tried echoing out both $e vars, but they are both fine.

If someone could point me in the right direction, I’d greatly appreciate it.

Advertisement

Answer

The result is:

<form style=”width:100px;></form>

Not sure what do you want exactly, but:

  • the style attribute is opened with a double quote, but not closed, causing the form to be not visible.
  • you didn’t parse the attributes perfectly as you miss the height and bgcolor. (separating with the space is not a good idea as some attributes can have space in the value)

HTML is fair complex, you might want to check out https://www.php.net/manual/en/class.domdocument.php to manipulate it without weird issues. You may change a few things with search&replace, but they will break easily.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement