当前位置: 动力学知识库 > 问答 > 编程问答 >

PHP Doesnt Work with ( ' ) symbols

问题描述:

I have a php script that uses something like this. But for some reason if i have any code with ' symbols in it, i get php errors when loading the page. So for some reason because of this i need to move all my javascripts to where html .='' doesnt exist.

But i need this code inside my site to work. How can i get codes with ' symbols into here?

For example below in this code we have 'linkText' which is the issue because of ' << this symbol

 $html .= '<input onClick="SelectAll('linkText');" id="linkText" class="sharelinkboxes" />

';

网友答案:

You have to escape ' characters with \:

$html .= '<input onClick="SelectAll(\'linkText\');" id="linkText" class="sharelinkboxes" />';
网友答案:

you have to escape the ' in a string

$html .= '<input onClick="SelectAll(\'linkText\');" id="linkText" class="sharelinkboxes" />';
网友答案:

Let us take a deeper look at what you are doing:-

  $html= '<input onClick="SelectAll('linkText');" id="linkText" class="sharelinkboxes" />';

When php encounters the second single quote just after the first bracket (' , it says "oh! this is the closing quote for the first single quote. That is where the bug begins. So you have to escape it just like below :-

$html= '<input onClick="SelectAll(\'linkText\');" id="linkText" class="sharelinkboxes" />';
网友答案:

You can do it like

$html .= <<< HTML
     <input onClick="SelectAll('linkText');" id="linkText" class="sharelinkboxes" />
HTML;

but 1 important thing do not put space after <<< HTML also do not put space before or after HTML;

or you can use

$html .= '<input onClick="SelectAll(\'linkText\');" id="linkText" class="sharelinkboxes" />';
分享给朋友:
您可能感兴趣的文章:
随机阅读: