Hertus Hertus - 1 year ago 55
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 "".

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download