0

I want to echo the following code:

<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;" class="delicious" target="_blank">Add to Delicious</a>

The problem is that Dreamweaver warns me on syntax errors I can not figure out. Who can spot the syntax errors? The html and script on its own works just fine - the problem comes with the php when it is echoed.

2
  • there must be more to your php than just the above. Commented Jul 16, 2010 at 11:41
  • are you trying to echo it with php e.g echo 'a href=""etc'; ? if so you will need to escape any single or double quotes depending on what you enclose your string in. e.g echo "<a href=\"delicious.com/save\""; etc Commented Jul 16, 2010 at 11:44

3 Answers 3

1

you can use:

<?php
echo '<a href="http://delicious.com/save" onclick="window.open(\'http://delicious.com/save?v=5&noui&jump=close&url=\'+encodeURIComponent(location.href)+\'&title=\'+encodeURIComponent(document.title), \'delicious\',\'toolbar=no,width=550,height=550\'); return false;" class="delicious" target="_blank">Add to Delicious</a>';
?>

not tested, but should work.

Sign up to request clarification or add additional context in comments.

Comments

1

You shouldn't have & in HTML, these should be encoded to &amp;.

<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;" class="delicious" target="_blank">Add to Delicious</a>

That's the only error I can spot.

Comments

0

You have to escape " chars :

echo "<a href=\"http://delicious.com/save\" onclick=\"window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;\" class=\"delicious\" target=\"_blank\">Add to Delicious</a>";

As bluesmoon said it's better written as :

echo <<<ENDOFECHO
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;" class="delicious" target="_blank">Add to Delicious</a>";
ENDOFECHO;

1 Comment

a HEREDOC would be better in this case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.