简体   繁体   中英

Trouble turning long concatenated variable into heredoc

$eventDropdowns ="<form method = \'get\' action = \'changer.php\'>";
$eventDropdowns.="<select name = \'change_event\' class = \'dropdown\' id = \'change_event\'><option value = \'\'>Failed loading records</option></select>";
$eventDropdowns.="<select name = \'event\' class = \'dropdown\' id = \'event\'><option value = \'\'>Failed loading records</option></select>";
$eventDropdowns.="<input  name = \'return\' type =\'hidden\' value = \'{$_SERVER['REQUEST_URI']}\'>";
$eventDropdowns.="<input type =\'submit\' value = \'CHANGE!\'>";
$eventDropdowns.="</form>";

I am fairly certain the quote style must be \\' because of where it is being placed in the script as it is surrounded by ' where it occurs in the PHP; PHP calling Javascript gets messy.

I am not sure if this is why I am unable to convert this ugly concatenated variable to heredoc .

echo "
  <div id = \"test\" 
  ondblclick = \"document.getElementById('test').innerHTML = '$eventDropdowns';\">
    Change Event
  </div>
";

When I convert $evenDropdowns into a heredoc, the whole page just loads blank, with no errors. However, when I leave it as it is, it works as I intended, when you double click the text within the div, it brings up a form that is populated via AJAX, and sends you to a different page for edits.

Thank you in advance.

I don't know why you'd be having trouble. A heredoc is ultra-easy to write. You just start spitting out text as if you were not in PHP mode, with the added benefit of being able to embed variables within the text. No escaping at all, * UNLESS you want to output a literal $ sign.

echo <<<EOL
<form method ="get" action="changer.php">
    <select name="change_event" class="dropdown" id="change_event">
         <option value="">Failed loading records</option>
    </select>
    <select name="event" class="dropdown" id="event">
         <option value="">Failed 
... etc...
EOL;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM