View Full Version : PHP error (String)
Dfraz
04-21-2008, 06:56 PM
echo "<a href="www.tizag.com" target="_blank" >Tizag Home</a>";
That gives me a error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/ocgroup/public_html/administratorcp/newsrow.php on line 27
Please help me, Thanks!!
Brandoe85
04-21-2008, 07:00 PM
Your double quotes are throwing it off. You either have to escape them or use single quotes:
echo '<a href="www.tizag.com" target="_blank" >Tizag Home</a>';
Check out the manual on escaping if you want take a look at that approach. Remember if you use single quotes anything within there is a literal....no interpolation with your variables.
Good luck
oesxyl
04-21-2008, 07:01 PM
echo "<a href="www.tizag.com" target="_blank" >Tizag Home</a>";
That gives me a error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/ocgroup/public_html/administratorcp/newsrow.php on line 27
Please help me, Thanks!!
echo '<a href="www.tizag.com" target="_blank" >Tizag Home</a>';
start and end echo with ' if you use inside ".
regards
Dfraz
04-21-2008, 07:08 PM
Ah, Thanks man! I giving you a rep and a thank.
Andrew Johnson
04-21-2008, 07:22 PM
You're better off using an escape character as this solution tends to get sticky if you ever need to echo something like:
<a href="http://andrewgjohnson.com" onclick="alert('test')">Link</a>
Because you are using both single and double quotes.
I'd suggest the following:
echo "<a href=\"www.tizag.com\" target=\"_blank\">Tizag Home</a>";
Dfraz
04-21-2008, 07:26 PM
That's what I tried doing but I think I did something wrong, You deserve a rep too!!
Inigoesdr
04-21-2008, 08:44 PM
You're better off using an escape character as this solution tends to get sticky if you ever need to echo something like:
<a href="http://andrewgjohnson.com" onclick="alert('test')">Link</a>
Because you are using both single and double quotes.
I'd suggest the following:
echo "<a href=\"www.tizag.com\" target=\"_blank\">Tizag Home</a>";
Any time you mix quotes in a string the situation becomes "sticky". Your solution isn't any better than the original because you have to escape quotes in both, and technically if you aren't parsing the string for variables you shouldn't use double-quotes for your string to begin with as it slows down the parser due to PHP interpolating the string.
Andrew Johnson
04-21-2008, 08:57 PM
I think mine is better for the reason I stated in my last post...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.