Saving PHP codes saved in MySQL

0

What is the best way to save small PHP code in the MySQL database so that it could be viewed, along with text saved in HTML in the database?

    
asked by anonymous 21.03.2018 / 12:48

1 answer

2

If you want to convert these codes to use as an example in your application ... Here is the tip.

Use the htmlentities function to encode PHP code. This function will convert all applicable characters into HTML entities, for example:

This code

<?php
    $variable = ["A", "B", "C"];
    var_export($variable);
?>

Will be transformed into:

&lt;?php

    $variable = [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;];
    var_export($variable);

?&gt;

Once you've done this, you'll be able to use it in your HTML as usual.

Meu código:
<pre>
    <code>
    &lt;?php
        $variable = [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;];
        var_export($variable);
    ?&gt;
    </code>
</pre>

To use this function, simply do the following:

<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);
?>
    
21.03.2018 / 12:56