Replace HTML tags [closed]

0

I have a page in PHP that displays POSTS (style BLOG).

Only sometimes I put some commands in the text itself (html tags etc).

How can I do to:

1 - - > If it has something like alert () it just shows on the page this command but does not execute it.

Thank you

    
asked by anonymous 30.05.2017 / 18:12

2 answers

1

To display the HTML elements, simply use the htmlentities function:

echo htmlentities("<script>alert('SOpt')</script>");

The output will be:

&lt;script&gt;alert('SOpt')&lt;/script&gt; 

And so the browser, instead of running the code, will only display it.

    
30.05.2017 / 19:31
-2

Well, I do not know if I understood very well, but as the alert you would have console.log ().

Instead of alert ('Hello world'), you would put console.log ('Hello world'). For Chrome, press F12 and open the console tab. So everything that you send through the console.log will be displayed in this tab silently, so the user will not be able to see. Note that this is for javascript codes.

In addition to the console.log, you have console.warn that displays text in dark yellow and with an exclamation mark, serves to draw attention. It also has the console.error that displays the message you want in the form of errors.

If you wanted to send a PHP variable to console.log, you could use this code:

<?php
    $array = array("um" => 1,"dois" => 2, 3, 4);
    $debug = json_encode($array);
    echo "<script>console.log($debug)</script>";
?>
    
30.05.2017 / 18:39