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" />
';
您必须使用\\
转义'
字符:
$html .= '<input onClick="SelectAll(\'linkText\');" id="linkText" class="sharelinkboxes" />';
您必须在字符串中转义'
$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" />';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.