473,503 Members | 3,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does this produce a parse error?

ucfirst({explode('/', $val)}[0])

This produces a parse error expecting ')', but why? I thought this was
perfectly valid code structuring in PHP!

Any ideas?

Phil
Jul 16 '05 #1
6 4046
With total disregard for any kind of safety measures "Phil Powell"
<so*****@erols.com> leapt forth and uttered:
ucfirst({explode('/', $val)}[0])

This produces a parse error expecting ')', but why? I thought
this was perfectly valid code structuring in PHP!

Any ideas?


Whoever told you you could do that?

--
There is no signature.....
Jul 16 '05 #2
Phil Powell wrote:
ucfirst({explode('/', $val)}[0])

This produces a parse error expecting ')', but why? I thought this was
perfectly valid code structuring in PHP!

Any ideas?

Phil


For some reason (I don't get it either),
PHP doesn't let you use the result of a built-in function
for operations like indexing.
You'll have to assign the result to a variable,
and index that variable.

The "expecting ')'" part of the error is because the { } are
illegal in this case, since they define a block,
which doesn't result in a return value.

Regards,
Felix

--
the QuiX project
Open Source software

E-Mail: qu**@free.fr
Web: http://www.quix.tk/

Jul 16 '05 #3
"Phil Powell" <so*****@erols.com> wrote in message
news:3GT_a.390$3M4.260@lakeread04...
ucfirst({explode('/', $val)}[0])

This produces a parse error expecting ')', but why? I thought this was
perfectly valid code structuring in PHP!


already said why it can't be done, but I can see what you are trying to
do, so here is an
solution perhaps:

consider:
<?

$var = "this is a test";

print ucfirst(current(explode(" ", $var)));

?>

Will output:
This

something like that you where looking for?

--
Vh
Dennis Friis
IRC: peavey - #linux.dk@undernet

Jul 16 '05 #4
Well, as much hate-mail as I'm going to get for saying this, but alas I
shall:

You can do that in Java. You can produce a result and index upon it as the
nature of OOP comes to mind.

I guess PHP isn't as OOP as I thought it was. :(

Phil
"the QuiX project" <qu**@free.fr> wrote in message
news:bh**********@news.hccnet.nl...
Phil Powell wrote:
ucfirst({explode('/', $val)}[0])

This produces a parse error expecting ')', but why? I thought this was
perfectly valid code structuring in PHP!

Any ideas?

Phil


For some reason (I don't get it either),
PHP doesn't let you use the result of a built-in function
for operations like indexing.
You'll have to assign the result to a variable,
and index that variable.

The "expecting ')'" part of the error is because the { } are
illegal in this case, since they define a block,
which doesn't result in a return value.

Regards,
Felix

--
the QuiX project
Open Source software

E-Mail: qu**@free.fr
Web: http://www.quix.tk/

Jul 16 '05 #5
Ok here we go:

this is my array elements:
$formFieldsArray = array('username/Username/text/1',
'password1/Password/password/1',
'password2/Password (for verification
purposes)/password/1',
'firstname/First Name/text/0', 'lastname/Last
Name/text/0',
'address1/Address/text/0', 'address2/Address Line
2/text/0',
'city/City/text/0', 'state/State/dropdown/0',
'zip/Zip - Postal/text/0',
'country/Country/dropdown/0',
'homephone/Home Phone/text/0', 'workphone/Work
Phone/text/0',
'fax/Fax/text/0',
'isRegisteredFromHome/Are you registering from
your home PC?/radio/0');

I want to get "state" and "country", from those parse "state.xml" and
"country.xml" into simple XML parsing 3-dimensional array structures, and
loop through those structures to populate a dropdown.

Ideas? I can't think of any dynamic way of doing it.

Phil

"Phil Powell" <so*****@erols.com> wrote in message
news:kYW_a.403$3M4.194@lakeread04...
That would work for the first one, (i.e., "This"), but what if I want to get "A" or "Test"?

Phil

"Dennis Friis" <pe******@PAM.placid.dk> wrote in message
news:3f**********************@nntp03.dk.telia.net. ..
"Phil Powell" <so*****@erols.com> wrote in message
news:3GT_a.390$3M4.260@lakeread04...
ucfirst({explode('/', $val)}[0])

This produces a parse error expecting ')', but why? I thought this was
perfectly valid code structuring in PHP!


already said why it can't be done, but I can see what you are trying to
do, so here is an
solution perhaps:

consider:
<?

$var = "this is a test";

print ucfirst(current(explode(" ", $var)));

?>

Will output:
This

something like that you where looking for?

--
Vh
Dennis Friis
IRC: peavey - #linux.dk@undernet


Jul 16 '05 #6
"Phil Powell" <so*****@erols.com> wrote in message
news:3GT_a.390$3M4.260@lakeread04...
ucfirst({explode('/', $val)}[0])

This produces a parse error expecting ')', but why? I thought this was
perfectly valid code structuring in PHP!

Any ideas?

Phil


ucfirst({explode('/', $val)}[0]) - curly brackets??
try
ucfirst(explode('/', $val)[0]);

Nathan


Jul 16 '05 #7

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

Similar topics

3
3944
by: Bruce W...1 | last post by:
Was browsing the documentation on reading a configuration file and found this. What does a semicolon do at the beginning of a line? ; <?php DO NOT REMOVE THIS LINE one = 1 five = 5 path =...
7
1742
by: chotiwallah | last post by:
suppose i have the following code: switch ($inc): case 0: require 'inc0.php'; break; case 1: require 'inc1.php'; break; case 2:
4
3423
by: WJA | last post by:
I'm probably missing something here but I can't understand the following. When 2 users try to save a record with the same primary key (a number field), the first record saves as expected, but the...
15
6702
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int...
4
4806
by: antonyliu2002 | last post by:
I have the following simple code to test if my session is working: <Script Runat="Server"> Sub LinkButtonGenInfo_Click(s As Object, e As EventArgs) If txtFirstName.Text <> Nothing Then...
10
4868
by: Viken Karaguesian | last post by:
Hello everyone, Me again. Trying to learn some more :>) I hope I got the terminology right. How does a browser parse (correct term?) an HTML document. I'm sure that every browser does it a...
7
2113
by: GS | last post by:
Hello, I'm receiving The state information is invalid for this page and might be corrupted error message when running code below. This happens on second post back. Why is it happening? My...
3
2109
by: Cor Pruim | last post by:
I have a very strange problem. I have written a Windows Service with VS2003 in vb.net. This service does some calculations and after that it needs to produce some Excel reports by getting data from...
13
2560
blazedaces
by: blazedaces | last post by:
Hey guys, how's it going today? So basically I have a program that uses hotbits (a real online random number generator based off radioactive decay) to produce truly random alphanumeric codes (Note:...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7315
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...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5559
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,...
1
4991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3158
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...
0
1492
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 ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
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...

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.