Saving PHP code saved in Mysql

Asked

Viewed 54 times

0

What is the best way to save small PHP codes in the Mysql database, so that they could be viewed eventually, along with texts saved in HTML in the database?

  • Coding with htmlentities

  • In case you want to compile the codes later ?

  • @Marcosbrinnerpikatoons think it will use including in the middle of the script, with some function, etc

1 answer

2

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


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

That 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 done, you can use in your HTML normally.

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, just do it as follows:

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

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);
?>
  • Guys, now it’s clear how to display PHP code saved in bd. I’ll open another question addressing how to compile PHP code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.