[PHP] unexpected T_ENCAPSED_AND_WHITESPACE

Discussion in 'Web Design & Coding' started by Glaanieboy, Mar 31, 2004.

  1. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    I am having problem with this specific bit of code:
    Code:
    $bb_img = "[ IMG]http://glaanieboy.dyndns.org/songviewer/songviewer.php?user=$name[ /IMG]";
    (don't mind the spaces in the IMG tags, the board parsed the IMG tags, instead of just displaying them, so I had to put spaces so the board won't parse them).

    It's been giving the "unexpected T_ENCAPSED_AND_WHITESPACE" error. When I remove the [ and ], the error is gone. If I escape them (by putting a \ before each bracket), the error is gone also, but the text is displayed with those escape characters, like this:
    Code:
    \[IMG\]http://glaanieboy.dyndns.org/songviewer/songviewer.php?user=$name\[/IMG\]
    Anyone has a solution? So far I haven't found anything on google.
     
  2. ignipotentis

    ignipotentis OSNN Addict

    Messages:
    127
    Its helpfull to know what exactly you are trying to do. What is the variable $name for. Why are you using bracketed image tags?
     
  3. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    It's for a website I am redesigning for my Winamp Songviewer Project (see signature). This part of the code is lifted from a page where you get after you have been succesfully registered to the site. The variable $name is the name of the registered user. Besides the standard welcome message, it also displays the code you must use to display the image on either your own website (HTML) or on a board using bbCode.
    Here is the rest of the relevant code (there are some MySQL queries before that, but I think you get the point):
    Code:
    $fetch_data = mysql_fetch_array($search_user);
    $name = $fetch_data['name'];
    $html_img = "<img src=\"http://glaanieboy.dyndns.org/songviewer/songviewer.php?user=$name\" border=\"0\">";
    //Here is the faulty line of code. This is where the brackets should be.
    $bb_img = "IMGhttp://glaanieboy.dyndns.org/songviewer/songviewer.php?user=$name/IMG";
    $html_enc_img = htmlentities($html_img, ENT_QUOTES);
    print "Welcome $name! Thank you for subscribing to the Winamp Songviewer Project! You can now login using the login
    form displayed above. After logging in, you can alter the looks of your personal signature.<br>
    <br>
    You can use this link for your website:<br>
    <code>$html_enc_img</code><br>
    <br>
    Or you can use bbCode for Bulletin Boards:<br>
    <code>$bb_img</code><br>
    <br>
    Have fun!";
     
  4. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    try maybe something like this
    $bb_img = "["."IMG"."]"."http://glaanieboy.dyndns.org/songviewer/songviewer.php?user=$name"."["."/IMG"."]";


    that breaks it up similar to how you have to break up the
    <?xml version="1.0" encoding="UTF-8" ?> XML declaration if you are using PHP
     
  5. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
  6. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    Both ways work. Thanks guys!
    X-Istence: I did thought of that, I was just wondering why it didn't parse the brackets.
     
  7. Nick

    Nick OSNN Lurker

    Messages:
    147
    Location:
    North West, UK
    Good to see its solved. Just out of curiosity, what causes the situation and how does breaking it up solve it?
     
  8. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    you just need the escape character as X pointed out \ or else it tries to parse the [ instead of printing it.

    PHP:
     echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
    prints <?xml version="1.0" encoding="ISO-8859-1"?>
     
  9. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Hehe, this just got to me.

    [] is used in array's. So if you set it to echo "[blah]" i personally would complain as well, where is the $var that belongs in front of it, which array do you want me to print "blah" from?

    Also j79zlr, i dont know if that would work PHP short open thing.
     
  10. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
  11. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Its a php.ini setting, it should be off.