PHP - Echoing multiple nested quotes of HTML

后端 未结 4 1383
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 18:13

I\'m attempting to echo the following line of HTML through PHP

echo \"

        
4条回答
  •  攒了一身酷
    2021-01-26 19:01

    They do get parsed properly, however you specified the wrong ones to use. Javascript can't differentiate between the quotes to wrap your string variables and the quotes to wrap the "onclick" value, it thinks the onclick ends too early.

    To differentiate them you'll have to escape them then. using \" for the ones inside the brackets.

    echo "

    ".$formattedDate." @ $time

    ";

    should do the trick.

    Alternatively, don't use echo for the whole string, simply output most of it direct:

    ?> //temporarily stop interpreting the file as PHP, so the next bit will be output directly as raw HTML
    

    ".$formattedDate." @ $time

提交回复
热议问题