[英]PHP Echo to a href - ' and "
I have a hint echo'd however, i have a issue with " and ' i can echo numerical values to the string, but not words.. 我有一个回显提示,但是我有一个与“和”的问题,我可以将数值回显到字符串,但不能回显单词。
$hint='<a href="javascript:void(0)"
onclick="javascript:document.contactForm.musicDetailTitle4.value=5;
document.contactForm.musicDetailArtist4.value=foo;">fill form</a>'.
5 works but foo doesn't works. 5有效,但是foo不起作用。
UPDATE 更新
Still not getting an output 仍然没有输出
$hint='<a href="javascript:void(0)" onclick="javascript:document.contactForm.itemDetailTitle4.value=\"$artist\"; document.contactForm.itemDetailArtist4.value=4;">fill form</a>'.
Whole Code 整个代码
echo $hint='<a href="javascript:void(0)" onclick="javascript:document.contactForm.itemDetailTitle4.value="'.$brand.'"; document.contactForm.itemDetailTitle4.value=4;">fill form</a>'.$artist."-".$title."-".$id."</a>";
Output is... 输出是...
<a href="javascript:void(0)" onclick="javascript:document.contactForm.itemDetailTitle4.value=" ";="" document.contactform.itemDetailTitle4.value="4;"">fill form</a>Tomato Soup-Heinz-0001<a href="javascript:void(0)" onclick="javascript:document.contactForm.itemDetailTitle4.value=" ";="" document.contactform.itemDetailTitle4.value="4;"">fill form</a>Tomato Soup-Heinz-0001
您需要转义报价
$hint='<a href="javascript:void(0)" onclick="javascript:document.contactForm.musicDetailTitle4.value=5; document.contactForm.musicDetailArtist4.value=\'foo\';">fill form</a>'.
It doesn't have much to do with PHP but rather JavaScript. 它与PHP无关,而与JavaScript无关。
When passing a numeric value you just pass the number itself, but when passing strings you must wrap them in quotations otherwise the compiler will mistake "foo" for a variable named foo
which may or may not exist. 当传递数值时,您只传递数字本身,但是当传递字符串时,必须将其用引号引起来,否则编译器会错误地将“ foo” foo
为可能存在或不存在的名为foo
的变量。
As others mentioned, all you have to do is wrap your string like so: \\'foo\\'
正如其他人提到的,您要做的就是像这样包装字符串: \\'foo\\'
The slashes are because you don't want to close your echo
which was also opened using a single quote, so you need to escape the character so when it's echoed to the user it will become 'foo'
. 斜杠是因为您不想关闭也使用单引号打开的echo
,因此您需要转义该字符,以便当它回显给用户时它将变为'foo'
。
Try this - 尝试这个 -
$hint='<a href="javascript:void(0)" onclick="javascript:document.contactForm.musicDetailTitle4.value=5; document.contactForm.musicDetailArtist4.value=\'foo\';">fill form</a>'.
When declaring a string value you must add quotes, and when adding it in this way you must escape those quotes using the \\
key. 声明字符串值时,必须添加引号,以这种方式添加时,必须使用\\
键对这些引号进行转义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.