views:

113

answers:

5

hello

i got this thing

<?
if (mysql_num_rows($say) == 1) {
    $a = "cicişsin!"; 
}
elseif (mysql_num_rows($say) == 0) {
    $a = "<a href='javascript:LaunchPopup('a2.php','250','1');'>ciciş yap</a>";
}
?>

but i cant echo second $a.. its exits at "javascript:LaunchPopup(" single quotes not shown

what can i do?

A: 

Use backslashes, something like this:

  $a = "<a href='javascript:LaunchPopup(\"a2.php\",\"250\",\"1\");'>ciciş yap</a>";
uthark
+10  A: 
$a = "<a href=\"javascript:LaunchPopup('a2.php','250','1');\">ciciş yap</a>";
Lucas
Lets be proper: $a = "<a href=\"#\" onclick=\"LaunchPopup('a2.php','250','1');return false;\">ciciş yap</a>";
David Murdoch
Beter, imho. $a = "<a href=\"a2.php\" onclick=\"LaunchPopup(this,'250','1');return false;\">cicis yap</a>"
Lucas
+1  A: 

Escape the quotes like this

"<a href=\"javascript:LaunchPopup(\'a2.php\',\'250\',\'1\');\">ciciş yap</a>"
Vinodh Ramasubramanian
A: 
$a = "<a href='javascript:LaunchPopup(a2.php,250,1)'>ciciş yap</a>";

will work for you

OM The Eternity
no, will not (15chars)
Rubens Farias
actually it will work.
Rakesh Juyal
@Rubens Can U be specific as I am getting the "javascript:LaunchPopup(a2.php,250,1)" oon task bar onb hovering the link... I believe it will work.
OM The Eternity
`a2.php` (without that quotes) can't be recognized as string; when you run, you'll get: `'a2' is undefined`; click that link and you'll see it
Rubens Farias
+3  A: 

Never use javascript: URLs. Put the URL in the href attribute where it belongs:

$a= '<a href="a2.php" onclick="LaunchPopup(this.href, 250, 1); return false;">ciciş yap</a>';

Now not only do you not have to worry about the escaping (assuming you can get away with passing numbers as the other arguments), but also your link now works properly when middle-clicked or bookmarked, instead of giving a JavaScript error.

Better still, unobtrusive scripting:

<a href="a2.php" class="popup">ciciş yap</a>

<script type="text/javascript">
    for (var i= document.links.length; i-->0;) {
        if (document.links[i].className==='popup') {
            document.links[i].onclick= function() {
                LaunchPopup(this.href, '250', '1');
                return false;
            }
        }
    }
</a>

Keep script code in scripts and out of markup, then you don't have to worry about HTML-escaping.

bobince