SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Escaping quotes

  1. #1
    SitePoint Evangelist jimday1982's Avatar
    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Escaping quotes

    I'm trying to store some popup code in a variable, but I'm having trouble with escaping the quotes I think. What I have is:

    PHP Code:
     $popcode "<SCRIPT LANGUAGE=\"JavaScript\" src=\"http://64.27.100.65/btest.js\"></SCRIPT>"
    $popcode .= "<SCRIPT LANGUAGE=\"JavaScript\">"
    $popcode .= "if (tP == 1) {"
    $popcode .= "document.write('<SCRIPT LANGUAGE=\"JavaScript\" src=\"http://www.popuptraffic.com/assign.php?l=jimday1982\"><\/script>');"
    $popcode .= "}"
    $popcode .= "else"
    $popcode .= "document.write('<SCRIPT LANGUAGE=\"JavaScript\" src=\"http://www.popuptraffic.com/assign.php?l=jimday1982&mode=layers\"><\/script>');"
    $popcode .= "</SCRIPT>" 
    The error I'm getting is: Parse error: parse error, unexpected T_VARIABLE in /home/day1982/public_html/index.php on line 4

    Can anyone tell me what I'm doing wrong?
    Jimmy Day
    Senior Systems Analyst
    Piedmont Healthcare Corporation

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You must end each statement with a semicolon.

    PHP Code:
     $popcode "<SCRIPT LANGUAGE=\"JavaScript\" src=\"http://64.27.100.65/btest.js\"></SCRIPT>";
    $popcode .= "<SCRIPT LANGUAGE=\"JavaScript\">";
    $popcode .= "if (tP == 1) {";
    $popcode .= "document.write('<SCRIPT LANGUAGE=\"JavaScript\" src=\"http://www.popuptraffic.com/assign.php?l=jimday1982\"><\/script>');";
    $popcode .= "}";
    $popcode .= "else";
    $popcode .= "document.write('<SCRIPT LANGUAGE=\"JavaScript\"; 
    Yours, Erik.

  3. #3
    SitePoint Evangelist jimday1982's Avatar
    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lilleman
    Hi,

    You must end each statement with a semicolon.

    PHP Code:
     $popcode "<SCRIPT LANGUAGE=\"JavaScript\" src=\"http://64.27.100.65/btest.js\"></SCRIPT>";
    $popcode .= "<SCRIPT LANGUAGE=\"JavaScript\">";
    $popcode .= "if (tP == 1) {";
    $popcode .= "document.write('<SCRIPT LANGUAGE=\"JavaScript\" src=\"http://www.popuptraffic.com/assign.php?l=jimday1982\"><\/script>');";
    $popcode .= "}";
    $popcode .= "else";
    $popcode .= "document.write('<SCRIPT LANGUAGE=\"JavaScript\"; 
    Yours, Erik.
    Thanks!
    Jimmy Day
    Senior Systems Analyst
    Piedmont Healthcare Corporation

  4. #4
    SitePoint Evangelist jimday1982's Avatar
    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I'm not getting any errors now, but it looks like something is still wrong with the code...When I use this code without storing into a variable:

    Code:
    <SCRIPT LANGUAGE="JavaScript" src="http://64.27.100.65/btest.js"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript">
    if (tP == 1) {
    document.write('<SCRIPT LANGUAGE=\"JavaScript\" src=\"http://www.popuptraffic.com/assign.php?l=jimday1982\"><\/script>');
    }
    else
    document.write('<SCRIPT LANGUAGE=\"JavaScript\" src=\"http://www.popuptraffic.com/assign.php?l=jimday1982&mode=layers\"><\/script>');
    </SCRIPT>
    It works, but when calling the variable in my first post ($popcode), it doesn't...does anyone see what I'm missing (I added the ;s already)?
    Jimmy Day
    Senior Systems Analyst
    Piedmont Healthcare Corporation

  5. #5
    SitePoint Evangelist jimday1982's Avatar
    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, for some reason, adding a line break after each line is printed out allowed it to work properly.
    Jimmy Day
    Senior Systems Analyst
    Piedmont Healthcare Corporation


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •