Hertus Hertus - 7 months ago 19
PHP Question

Syntax error in echo out "<a href="

I need to echo this code:

<a href="javascript:toggle('test')"> x Click.</a>

I tried it like this:

if (!empty($item['criteria'])) {
foreach ($item['criteria'] as $item2){
echo "<a href="javascript:toggle('test')>Click</a>";
echo '<div id="'. test.'" style="display: none">'. $item2['description'].'</div>';

I think there is a mistake with the "".


You're looking for something like this:

if (!empty($item['criteria'])) {
    foreach ($item['criteria'] as $item2) {
        echo "<a href=\"javascript:toggle('test');\">Click</a>";
        echo '<div id="' . 'test' . '" style="display: none">'. $item2['description'].'</div>';

You need to properly escape your quotes inside strings.