Why does this produce a parse error?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Powell

    Why does this produce a parse error?

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

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

    Any ideas?

    Phil


  • Phil Roberts

    #2
    Re: Why does this produce a parse error?

    With total disregard for any kind of safety measures "Phil Powell"
    <soazine@erols. com> leapt forth and uttered:
    [color=blue]
    > ucfirst({explod e('/', $val)}[0])
    >
    > This produces a parse error expecting ')', but why? I thought
    > this was perfectly valid code structuring in PHP!
    >
    > Any ideas?
    >[/color]

    Whoever told you you could do that?

    --
    There is no signature.....

    Comment

    • the QuiX project

      #3
      Re: Why does this produce a parse error?

      Phil Powell wrote:[color=blue]
      > ucfirst({explod e('/', $val)}[0])
      >
      > This produces a parse error expecting ')', but why? I thought this was
      > perfectly valid code structuring in PHP!
      >
      > Any ideas?
      >
      > Phil[/color]

      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: quix@free.fr
      Web: http://www.quix.tk/

      Comment

      • Dennis Friis

        #4
        Re: Why does this produce a parse error?

        "Phil Powell" <soazine@erols. com> wrote in message
        news:3GT_a.390$ 3M4.260@lakerea d04...[color=blue]
        > ucfirst({explod e('/', $val)}[0])
        >
        > This produces a parse error expecting ')', but why? I thought this was
        > perfectly valid code structuring in PHP![/color]

        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@under net

        Comment

        • Phil Powell

          #5
          Re: Why does this produce a parse error?

          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" <quix@free.fr > wrote in message
          news:bhh1v7$i6c $1@news.hccnet. nl...[color=blue]
          > Phil Powell wrote:[color=green]
          > > ucfirst({explod e('/', $val)}[0])
          > >
          > > This produces a parse error expecting ')', but why? I thought this was
          > > perfectly valid code structuring in PHP!
          > >
          > > Any ideas?
          > >
          > > Phil[/color]
          >
          > 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: quix@free.fr
          > Web: http://www.quix.tk/
          >[/color]


          Comment

          • Phil Powell

            #6
            Re: Why does this produce a parse error?

            Ok here we go:

            this is my array elements:
            $formFieldsArra y = 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',
            'isRegisteredFr omHome/Are you registering from
            your home PC?/radio/0');

            I want to get "state" and "country", from those parse "state.xml" and
            "country.xm l" 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" <soazine@erols. com> wrote in message
            news:kYW_a.403$ 3M4.194@lakerea d04...[color=blue]
            > That would work for the first one, (i.e., "This"), but what if I want to[/color]
            get[color=blue]
            > "A" or "Test"?
            >
            > Phil
            >
            > "Dennis Friis" <peavzNOS@PAM.p lacid.dk> wrote in message
            > news:3f3c1c76$0 $7811$ba624c82@ nntp03.dk.telia .net...[color=green]
            > > "Phil Powell" <soazine@erols. com> wrote in message
            > > news:3GT_a.390$ 3M4.260@lakerea d04...[color=darkred]
            > > > ucfirst({explod e('/', $val)}[0])
            > > >
            > > > This produces a parse error expecting ')', but why? I thought this was
            > > > perfectly valid code structuring in PHP![/color]
            > >
            > > 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@under net
            > >[/color]
            >
            >[/color]


            Comment

            • treefroginometry

              #7
              Re: Why does this produce a parse error?

              "Phil Powell" <soazine@erols. com> wrote in message
              news:3GT_a.390$ 3M4.260@lakerea d04...[color=blue]
              > ucfirst({explod e('/', $val)}[0])
              >
              > This produces a parse error expecting ')', but why? I thought this was
              > perfectly valid code structuring in PHP!
              >
              > Any ideas?
              >
              > Phil[/color]

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

              Nathan






              Comment

              Working...