• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[PHP] unexpected T_ENCAPSED_AND_WHITESPACE

#1
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.
 
#3
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
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
 

j79zlr

Glaanies script monkey
Political User
#8
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 User
#9
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 posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,240
Members
89,015
Latest member
loxioalix