Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Php Syntax Question
awesomebill61
post Feb 22 2008, 12:52 AM
Post #1


Newbie [Level 3]
***

Group: [HOSTED]
Posts: 48
Joined: 21-January 08
Member No.: 56,591



this is an error i have dealt with for a long time and it doesn't really make much sense to me.

if i am parsing a string, and try to put an array variable in it, it returns an error
example:
CODE
echo "This is a variable: $array['var']";

that will return an error.
I have tried to get around it by doing
$array[\'var\']
and
$array[\"var\"]
but those just return different errors. I can get rid of the error by using this:
$array[var]
but it says right in the php manual that that is a no-no

the only two ways i know to escape are to assign the value to a string variable or to concatenate.
CODE
$var = $array['var'];
echo "This is a variable: $var"

CODE
echo "This is a variable: " . $array['var'];


the first is rather cumbersome with large arrays, and the second is kind of messy the way i see it.
does anyone know how to get around this?
Go to the top of the page
 
+Quote Post
sonesay
post Feb 22 2008, 01:19 AM
Post #2


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 681
Joined: 20-June 07
From: Auckland
Member No.: 45,102



I dont know what it's called but I came across it somewhere.. cant remember that either lol. anywhere here it is and this is what i use


CODE
echo"<span class='header'>Title</span> {$rs['title']}";


if I don't use the {} around the array/resource, it won't work. hope that helps ya out and if anyone can shed some light on its former name and use of the {} in this case, it would be appreciated.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. 3d Landscape In Swishmax (flash)(1)
  2. Question On The "p=pageid" Syntax(4)
  3. Parse Error: Syntax Error, Unexpected '<' On Line 29(11)
  4. Syntax Highlighting For Code(4)


 



- Lo-Fi Version Time is now: 8th September 2008 - 06:13 PM