php - Problems with embedded apex in a string? -


how can write more embedded " , ' in php ? example, dunno how write html complete element apex:

as can see, use '' php string. inside, use "", need level of apix , dunno how write 1 in php document. (php thinks string complete in middle because sees ' before end.

$output .= '<img style="outline:none;" src="sites/default/unselect.png" alt="unselect all" onclick='$(this).siblings('.form-item').each(function(index){ $('input:checkbox', this).attr('checked', ''); });'/>'; 

how can solve ?

thanks

there many ways solve that. listed best worst

1) use templating engine , keep php , html separate. also, use non-obtrusive javascript , avoid javascript code in html tags

2) when outputting complex html, escape php mode , print strings is.

function foo() { ?>        complex html <?php      php continues here  } // foo 

3) use heredoc syntax avoid quoting issues

$output .= <<<text    <img style="outline:none;" src="sites/default/unselect.png" alt="unselect all" onclick='$(this).siblings('.form-item').each(function(index){ $('input:checkbox', this).attr('checked', ''); });'/> text; 

4) escape quotes others said


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -