By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,965 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,965 IT Pros & Developers. It's quick & easy.

Why does this produce a parse error?

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.