473,801 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing superglobal elements

Hello!

I see that I can access a superglobal element using the index this
way:

print("<p>$_GET[surname]</p>"); //(element index without any
delimiters within a double-quotation-mark-delimited string)

But not this way:

print("<p>$_GET['surname']</p>"); //(apostroph-delimited element index
within a double-quotation-mark-delimited string)

The latter gives me an error message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING
Why is that? (I cant understand why PHP gets confused by that)

Is this configurable?

Thanks
Michael
Nov 22 '07 #1
3 1583
Michaelp wrote:
Hello!

I see that I can access a superglobal element using the index this
way:

print("<p>$_GET[surname]</p>"); //(element index without any
delimiters within a double-quotation-mark-delimited string)

But not this way:

print("<p>$_GET['surname']</p>"); //(apostroph-delimited element index
within a double-quotation-mark-delimited string)

The latter gives me an error message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING
Why is that? (I cant understand why PHP gets confused by that)

Is this configurable?

Thanks
Michael
Actually, the first should give you a notice, also. But you evidently
have notices disabled.

And no, you can't configure it. Just use curly braces, i.e.

print("<p>{$_GE T['surname']}</p>");
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 22 '07 #2
On Thu, 22 Nov 2007 21:32:40 +0100, Michaelp <mi******@hio.n owrote:
Hello!

I see that I can access a superglobal element using the index this
way:

print("<p>$_GET[surname]</p>"); //(element index without any
delimiters within a double-quotation-mark-delimited string)

But not this way:

print("<p>$_GET['surname']</p>"); //(apostroph-delimited element index
within a double-quotation-mark-delimited string)

The latter gives me an error message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING
Why is that? (I cant understand why PHP gets confused by that)
Posted the links only days ago, but here you go:
http://nl2.php.net/manual/en/languag...string.parsing

So, use:
"<p>{$_GET['surname']}</p>"

(Well, actually, don't, unless you're sure you've checked the GET variable
for XSS attacks.
--
Rik Wasmus
Nov 22 '07 #3
Rik is right--the curly's {} will do what you want to do, and you
should clean your variables from the user. PHP has some built-in
methods, but Cal Henderson has an even better way to do this:

http://www.iamcal.com/publish/articl...g_html_part_2/


On Nov 22, 2:47 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
On Thu, 22 Nov 2007 21:32:40 +0100, Michaelp <micha...@hio.n owrote:
Hello!
I see that I can access a superglobal element using the index this
way:
print("<p>$_GET[surname]</p>"); //(element index without any
delimiters within a double-quotation-mark-delimited string)
But not this way:
print("<p>$_GET['surname']</p>"); //(apostroph-delimited element index
within a double-quotation-mark-delimited string)
The latter gives me an error message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING
Why is that? (I cant understand why PHP gets confused by that)

Posted the links only days ago, but here you go:http://nl2.php.net/manual/en/languag...language.types...

So, use:
"<p>{$_GET['surname']}</p>"

(Well, actually, don't, unless you're sure you've checked the GET variable
for XSS attacks.
--
Rik Wasmus
Nov 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3196
by: Rainer Erismann | last post by:
Hi, i have a variable (well, an Object) which is needed in beneath every Script. it's not needed to be changed during the whole script, so i like to access it easyli without passing by or declare it as global in every function. afaik it isnt possible to set a variable to superglobal. Is there any reason why i shouldn't add it to the _SERVER array or any other superglobal? Thanks
1
2909
by: Bruce Lehmann | last post by:
Hi, I've installed Apache (WAMP install) so I can edit and test my web site on my home computer. In general php code seems to work, but I can't access Apache variables such as PATH or SCRIPT_NAME. The code below works perfectly when I upload it to my webhost server. However, at home, everything processes corectly except the environmental variables are blank.
5
2455
by: Craig Anderson | last post by:
Can anyone tell me the best way to access a hidden object in a form? I could use a hard-coded index to the elements of the form, but it's too easy to add something before the hidden object and mess up the indexing. For example: The form has a tagid of "myForm" The hidden object has a tagId of "myHiddenObj"
6
2747
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is called "form1", and I have selects called "PORTA", "PORTB" ... etc...
9
5749
by: Super Mango | last post by:
Hi - Is it possible to change the status of a variable to superglobal so it'll be valid inside functions without declaring it with "global" inside each function? Thanks -
1
3142
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
3
1564
by: mtjarrett | last post by:
i having trouble accessing the values from superglobal arrays. there are two situations but i'm pretty sure it's the same problem. here's the deal: on page1.php i have several check boxes. before listing them i have the code $info = array(); and then each checkbox has
1
1718
by: Greg Scharlemann | last post by:
There is probably an easy solution to this that I've overlooked somewhere... I have a main file, call it main.php, and an include file, myInclude.php. I'm accessing main.php via: http://www.example.com/main.php?page=new&var1=test&var2=test2 main.php: ------------------- <?php
3
10524
by: judy.j.miller | last post by:
Does anyone know why i can't access a form element value using dot notation in firefox, when i'm in a function. Works ok in the body. I'm trying to do this: var FarTemp = faren.temp.value; I can get at the value using the array method, the getelements by id method, and the bracket-with-the-element-name in it method. But the dot notation doesn't work, in firefox, in the function (which i have in the head).
0
9697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10291
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10049
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9100
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6827
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.