开发者

trouble using hidden input value with quotes

开发者 https://www.devze.com 2023-03-18 18:11 出处:网络
I searched the site and didn\'t find a solution. My problem is that I\'ve got a hidden input that I want to send via the post method that has quotes in it. I\'ve tried using addslashes() and I get the

I searched the site and didn't find a solution. My problem is that I've got a hidden input that I want to send via the post method that has quotes in it. I've tried using addslashes() and I get the same problem. It looks something like this right now:

<?php $value = 'I\'ve got \"some\" random text with quotes'; ?>
<i开发者_StackOverflownput name="example" value="<?=$value?>">

And I get most of the the text showing in my form because the quotes aren't being ignored AARGH! ;) So how to I get text with quote into a hidden input?

Thanks in advance!


<?php $value = "I've got \"some\" random text with quotes"; ?>

when you output this will result in the following?

<input name="example" value="I've got \"some\" random text with quotes">


I would convert them so they validate and avoid confusion:

<?php $value = 'I&#039;ve got &quot;some&quot; random text with quotes'; ?>
<input name="example" value="<?=$value?>">

Try to avoid using double quotes with PHP strings, as PHP will search the entire string for a variable to parse, regardless if the string contains one. They are slower than single quotes. Not so much anymore these days, but still a good practice to use single quotes for strings.

0

精彩评论

暂无评论...
验证码 换一张
取 消