[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.
 
Its helpfull to know what exactly you are trying to do. What is the variable $name for. Why are you using bracketed image tags?
 
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!";
 
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
 
Both ways work. Thanks guys!
X-Istence: I did thought of that, I was just wondering why it didn't parse the brackets.
 
Good to see its solved. Just out of curiosity, what causes the situation and how does breaking it up solve it?
 
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"?>
 
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

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
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.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,620
Latest member
alexexists11
Back