[PHP] unexpected T_ENCAPSED_AND_WHITESPACE

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
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.
 

ignipotentis

OSNN Addict
Joined
25 Mar 2004
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?
 

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
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!";
 

Geffy

OSNN Veteran Addict
Joined
18 Mar 2002
Messages
7,805
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
 

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
Both ways work. Thanks guys!
X-Istence: I did thought of that, I was just wondering why it didn't parse the brackets.
 

Nick

OSNN Lurker
Joined
10 Feb 2004
Messages
147
Good to see its solved. Just out of curiosity, what causes the situation and how does breaking it up solve it?
 

j79zlr

Glaanies script monkey
Political Access
Joined
16 Feb 2003
Messages
2,725
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"?>
 

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
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.
 

Members online

No members online now.

Latest profile posts

Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?

Forum statistics

Threads
62,005
Messages
673,461
Members
5,599
Latest member
Larry Chris