Forum Moderators: coopster
html_entity_decode($variable, ENT_QUOTES, 'UTF-8');
htmlentities(html_entity_decode($variable, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
$d = 'phpinfo();';
$e = str_split($d); unset($d);
print_r($e); echo '<br>';
foreach ($e as $char) {
echo $char;
}
use an array with explode because individual characters cannot be executed/have no meaning. right? so less than is just less than without the whole line.
The <script> <b>tag is used to embed a client-side script</b>... The <script> tag is used to embed a client-side script...
[edited by: robzilla at 10:43 am (utc) on Sep 6, 2020]
phpinfo() is not executed and ugly htmlspecialchars is avoided.
does php execute php commands in a string comparison or not?
the problem with htmlspecialchars: i use it to encode input before inserting that input into the database. Thus, the output is entity encoded: <script> so even if the text is unsafe code, i'd like to reverse the encoding without it being executed.
actually, i use htmlspecialchars on all text inserted into my db and again htmlspecialchars on all data returned from the db before i use it.
i don't even trust data coming from my db. maybe i didn't put it there and it isn't escaped.
//imagine $a is inserted into my database
//i also use htmlspecialchars to encode results from a select query as in $aa
$a = '<script>alert("see?")</script>';
$aa = htmlspecialchars($a); //thus, $aa is the $result column data ($a) from a query
//now the code is html escaped twice, which is quite ugly. I need it cleaned and displayed without execution.
$char = trim(html_entity_decode($aa, ENT_QUOTES, 'UTF-8'));
$char = html_entity_decode($char, ENT_QUOTES, 'UTF-8');
$char = htmlentities(html_entity_decode($char, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
echo $char;
echo '<br><br>';
the above code works in every browser that i've tested: ie11, edge 44, edge chromium, firefox 50-80, chrome etc
the script is displayed but not executed. is this method safe and correct?
<script>alert("see?")</script> <script>alert("see?")</script> <script>alert(\"see?\")</script> <script>alert("see?")</script> <script>alert("see?")</script> <script>alert("see?")</script> <script>alert("see?")</script> <script>alert("see?")</script> &lt;script&gt;alert("see?")&lt;/script&gt; <script>alert("see?")</script> <script>alert("see?")</script> <script>alert("see?")</script> <script>alert("see?")</script>