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.
asked Jul 16, 2010 at 11:33
Thomas
5891 gold badge10 silver badges20 bronze badges
-
there must be more to your php than just the above.bluesmoon– bluesmoon2010年07月16日 11:41:16 +00:00Commented 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\""; etcLuke– Luke2010年07月16日 11:44:55 +00:00Commented Jul 16, 2010 at 11:44
3 Answers 3
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.
answered Jul 16, 2010 at 11:53
ahmet2106
5,0174 gold badges30 silver badges41 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You shouldn't have & in HTML, these should be encoded to &.
<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>
That's the only error I can spot.
answered Jul 16, 2010 at 11:36
Markus Hedlund
24.4k22 gold badges82 silver badges114 bronze badges
Comments
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;
answered Jul 16, 2010 at 12:03
Toto
91.7k63 gold badges97 silver badges135 bronze badges
1 Comment
bluesmoon
a HEREDOC would be better in this case
default