$document = "<html><head></head><body><b>Hi</b><?php echo \"lol\";?><br></body></head></html>"; function shighlight($document) { // Преобразуем угловые скобки для отображения HTML-тегов $document = str_replace("<", "&lt", $document); $document = str_replace(">", "&gt", $document); // Преобразуем теги PHP <?php и ? > $tegs = array("'&lt;\?php'i","'&lt;\?'i","'\?&gt;'i"); $replace = array( "<font color=#95001E>&lt;?php</font>", "<font color=#95001E>&lt;?</font>", "<font color=#95001E>?&gt;</font>",); $document = preg_replace($tegs, $replace, $document); echo($document); } shighlight($document); 

I just can not understand why it does not process the template, it does not produce errors.

Closed due to the fact that off-topic participants Dmitriy Simushev , ReinRaus , Nicolas Chabanovsky 22 May '16 at 6:47 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Dmitriy Simushev, ReinRaus, Nicolas Chabanovsky
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • There are no telepaths. What exactly is wrong? - korytoff
  • 2
    In both str_replace, you need to add a semicolon to the replacement. - Visman
  • I don't understand what you want to achieve, but can htmlentities ($ document) be easier? - splash58
  • str_replace works as it should, the point is that the string is not processed by the template. As a result, on the output, we get a string without syntax highlighting. - DaVASrK

1 answer 1

There is no str_replace replacement ; , and in the preg_replace regular preg_replace check for this character.

It should be like this:

 $document = str_replace("<", "&lt;", $document); $document = str_replace(">", "&gt;", $document);