I have a string that has a value with an html tag and this string I want to put in a hidden input type. This is for now:
$str = "som'e text <img src="img/src.jpg">.. <a href="link">link</a>";
echo '<input type="hidden" name="val" value="'.$str.'">';
I did this in order for it to be saved in my database to be show again, but the issue is it looks like this:
<input type="hidden" name="val" value="som'e text <img src="img/src.jpg">.. <a href="link">link</a>">
Any ideas?
You can't reuse quotes over and over within your string concatentator as they'll break the interpreter. Instead, escape the inner quotes with backslashes.
$str = "som'e text <img src=\"img/src.jpg\">.. <a href=\"link\">link</a>";
Try base64_encode()
and base64_decode()
php function.
<?php
$str = "som'e text <img src=\"img/src.jpg\">.. <a href=\"link\">link</a>";
echo '<input type="hidden" name="val" value="'.base64_encode($str).'">';
and get the POST value as:
$val = base64_decode($_POST['val']);
[Remember to escape the strings properly]
You should use base64_encode()
for this.. and use base64_decode()
for getting original text.
and I will highly recommend you to use parameterized
way to insert in database if you are not using.. PDO With Php