There is a variable in php

$mess=" <table border="0" cellpadding="0" cellspacing="0" style="margin:0; padding:0;width:100%"> <tr> <td ><img src="http://www.gociss.zz.mu/img/mail/1.png" onmouseover="this.src=\'http://www.gociss.zz.mu/img/mail/1_.png\';" onmouseout="this.src=\'http://www.gociss.zz.mu/img/mail/1.png\';" /></td> <td style=""><img src="http://www.gociss.zz.mu/img/mail/2.png" onmouseover="this.src=\'http://www.gociss.zz.mu/img/mail/2_.png\';" onmouseout="this.src=\'http://www.gociss.zz.mu/img/mail/2.png\';" /></td> <td ><img src="http://www.gociss.zz.mu/img/mail/3.png" onmouseover="this.src=\'http://www.gociss.zz.mu/img/mail/3_.png\';" onmouseout="this.src=\'http://www.gociss.zz.mu/img/mail/3.png\';" /></td> <td ><img src="http://www.gociss.zz.mu/img/mail/4.png" onmouseover="this.src=\'http://www.gociss.zz.mu/img/mail/4_.png\';" onmouseout="this.src=\'http://www.gociss.zz.mu/img/mail/4.png\';" /></td> </tr> <tr> </tr> </table> " 

Help arrange true quotes inside variable, what would be right

    4 answers 4

    everyone meets this problem. Ways of withdrawal have been proposed: Visman, toxxxa, Arthur Dan'ko.

    The way to figure it out:

    • use the editor with highlighting of your programming language or IDE
    • use special character escaping rules
    • Use the information for which certain quotes are used ( " - in the text, wrapped double quotes, variable substitution occurs, ' - use to display text)
    • move from left to right. After fixing or replacing quotes, the environment will highlight everything is in order.

    ps: Using such code is bad practice. Why, yes, because such code is not readable and causes complications out of the blue. Perhaps this will change to review MVC themes and template engines.

      You can try to drive the variable body into single quotes first, so as not to escape double ...

       <?php $mess= ' <table border="0" cellpadding="0" cellspacing="0" style="margin:0; padding:0;width:100%"> <tr> <td> <img src="http://www.gociss.zz.mu/img/mail/1.png" onmouseover="this.src="http://www.gociss.zz.mu/img/mail/1_.png";" onmouseout="this.src="http://www.gociss.zz.mu/img/mail/1.png";" /> </td> <td style=""> <img src="http://www.gociss.zz.mu/img/mail/2.png" onmouseover="this.src="http://www.gociss.zz.mu/img/mail/2_.png";" onmouseout="this.src="http://www.gociss.zz.mu/img/mail/2.png";" /> </td> <td> <img src="http://www.gociss.zz.mu/img/mail/3.png" onmouseover="this.src="http://www.gociss.zz.mu/img/mail/3_.png";" onmouseout="this.src="http://www.gociss.zz.mu/img/mail/3.png";" /> </td> <td> <img src="http://www.gociss.zz.mu/img/mail/4.png" onmouseover="this.src="http://www.gociss.zz.mu/img/mail/4_.png";" onmouseout="this.src="http://www.gociss.zz.mu/img/mail/4.png";" /></td> </tr> <tr> </tr> </table>'; echo $mess; ?> 

        Since your text is framed with double quotes, all double quotes in the text need to be escaped.

         <table border=\"0\" cellpadding=\"0\" cellspa... 
        • and single also screened? - zkolya 5:44 pm
        • I've fixed it, but it doesn't work - zkolya 5:46 pm
        • In this case, single shielding is generally not necessary, only double ones. - Visman 5:46 pm

        You can escape nothing, but simply replace the most "external quotes" with this construct:

         $mess = <<_END ... _END; 

        Where _END is any label. The main thing is to match both tags: at the beginning and at the end. This construct is called HereDoc and works like double quotes. If the label is enclosed in single quotes, then this construct will be called NowDoc and works accordingly as single quotes.