Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Possible Duplicate:
Creating javscript function to destroy php session

Hi I am trying to create a php variable that will display itself as a popup. Here is the code I have...

    <?php 
 // this starts the session 
 session_start(); 
 $var = "";

 // echo variable from the session, we set this on our other page 
 if ($_SESSION['color'] == "") {
        $var = "<a href='JavaScript:newPopup('http://www.yourfantasyfootballreality.com/signin.php');' class='two'>Sign In</a>";
    } else {
    echo "Hello, ";
    }
 echo $var;
 ?> 

I can't seem to arrange the semicolons and quotes correctly. Can someone please show me how this is done.

share|improve this question
add comment (requires an account with 50 reputation)

marked as duplicate by BoltClock Jun 16 '12 at 6:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

You can escape the quote character you are using to delimit your string within the string with the escape character (\)...

$var = "<a href=\"JavaScript:newPopup('http://www.yourfantasyfootballreality.com/signin.php');\" class=\"two\">Sign In</a>";

Alternatively, you can mix quotes, i.e. use single quotes to delimit your string and double quotes for quotes around your attributes or vice versa.

You could also use heredoc or nowdoc.

share|improve this answer
Thanks for removing a downvote :) – alex Jun 16 '12 at 1:56
add comment (requires an account with 50 reputation)

In "<a href='JavaScript:newPopup('http://www.yourfantasyfootballreality.com/signin.php');' class='two'>Sign In</a>"; the 2nd ' closes the href tag. You need to escape it, so you would do something like:

$var = "<a href='JavaScript:newPopup(\"http://www.yourfantasyfootballreality.com/signin.php\");' class='two'>Sign In</a>";

So that when it actually outputs you get <a href='JavaScript:newPopup("http://www.yourfantasyfootballreality.com/signin.php");' class='two'>Sign In</a>

share|improve this answer
add comment (requires an account with 50 reputation)

Not the answer you're looking for? Browse other questions tagged or ask your own question.