Parse part of string (mid string function ?)

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

    #1

    Parse part of string (mid string function ?)

    Can someone tell me how to parse part of a string? I can use the following:

    <?php
    $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url);
    echo $text;
    ?>

    to get this result:

    "Your currently at /test.php "

    I just want to get "test.php " without the dash. I also need to parse out
    parts of other strings. I know how to use Mid(), Left(), and Right() in VB,
    but no clue for PHP.

    Thanks in advance for the assistance.



  • Pedro

    #2
    Re: Parse part of string (mid string function ?)

    mimages wrote:[color=blue]
    > Can someone tell me how to parse part of a string? I can use the following:[/color]
    [...][color=blue]
    > I know how to use Mid(), Left(), and Right() in VB,
    > but no clue for PHP.[/color]

    check the substr() function @ http://www.php.net/substr.

    --
    I have a spam filter working.
    To mail me include "urkxvq" (with or without the quotes)
    in the subject line, or your mail will be ruthlessly discarded.

    Comment

    • Geoff Berrow

      #3
      Re: Parse part of string (mid string function ?)

      I noticed that Message-ID:
      <9VAcb.24771$Ci 5.563011@twiste r.tampabay.rr.c om> from mimages contained
      the following:
      [color=blue]
      > <?php
      > $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url);
      > echo $text;
      >?>
      >
      >to get this result:
      >
      > "Your currently at /test.php "
      >
      >I just want to get "test.php " without the dash.[/color]

      <?php
      $text = str_replace("/","","$_SER VER[PHP_SELF]");
      echo $text;
      ?>

      --
      Geoff Berrow
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • Ian.H

        #4
        Re: Parse part of string (mid string function ?)

        On Thu, 25 Sep 2003 14:36:53 +0100, Geoff Berrow wrote:
        [color=blue]
        > I noticed that Message-ID:
        > <9VAcb.24771$Ci 5.563011@twiste r.tampabay.rr.c om> from mimages contained
        > the following:
        >[color=green]
        >> <?php
        >> $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url); echo
        >> $text;
        >>?>
        >>
        >>to get this result:
        >>
        >> "Your currently at /test.php "
        >>
        >>I just want to get "test.php " without the dash.[/color]
        >
        > <?php
        > $text = str_replace("/","","$_SER VER[PHP_SELF]");
        > echo $text;
        > ?>[/color]


        $text = array_pop(split ('/', $_SERVER['PHP_SELF']));
        echo $text;


        Just as another example.. although not tested for efficiency =)



        Regards,

        Ian

        --
        Ian.H [Design & Development]
        digiServ Network - Web solutions
        www.digiserv.ne t | irc.digiserv.ne t | forum.digiserv. net
        Programming, Web design, development & hosting.

        Comment

        • medi

          #5
          Re: Parse part of string (mid string function ?)


          "mimages" <mimages@NOSPAM spvision.com> wrote in message
          news:9VAcb.2477 1$Ci5.563011@tw ister.tampabay. rr.com...[color=blue]
          > Can someone tell me how to parse part of a string? I can use the[/color]
          following:[color=blue]
          >
          > <?php
          > $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url);
          > echo $text;
          > ?>
          >
          > to get this result:
          >
          > "Your currently at /test.php "
          >
          > I just want to get "test.php " without the dash. I also need to parse out
          > parts of other strings. I know how to use Mid(), Left(), and Right() in[/color]
          VB,[color=blue]
          > but no clue for PHP.
          >
          > Thanks in advance for the assistance.[/color]

          <?php

          $text = basename($_SERV ER['PHP_SELF']);
          echo $text;

          ?>



          Comment

          • David Gillen

            #6
            Re: Parse part of string (mid string function ?)

            An noise sounding like Ian.H said:[color=blue]
            > On Thu, 25 Sep 2003 14:36:53 +0100, Geoff Berrow wrote:
            >[color=green]
            >> I noticed that Message-ID:
            >> <9VAcb.24771$Ci 5.563011@twiste r.tampabay.rr.c om> from mimages contained
            >> the following:
            >>[color=darkred]
            >>> <?php
            >>> $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url); echo
            >>> $text;
            >>>?>
            >>>
            >>>to get this result:
            >>>
            >>> "Your currently at /test.php "
            >>>
            >>>I just want to get "test.php " without the dash.[/color]
            >>
            >> <?php
            >> $text = str_replace("/","","$_SER VER[PHP_SELF]");
            >> echo $text;
            >> ?>[/color]
            >
            >
            > $text = array_pop(split ('/', $_SERVER['PHP_SELF']));
            > echo $text;
            >
            >
            > Just as another example.. although not tested for efficiency =)
            >[/color]
            You didn't test your code works so as to answer more questions, thus improving
            your efficiency

            or
            You didn't test the speed your code ran an vs the speed of the other to see
            which was more efficient

            ??????

            Dave.
            --

            I'm a dead man, and buggered to boot!

            Comment

            • mimages

              #7
              Re: Parse part of string (mid string function ?)

              Wow, basename, I don't think I'd have thought of this one. I'll try it.
              Thanks!

              "medi" <medi@banjaluka .com> wrote in message
              news:bkuq06$elk $1@news.teol.ne t...[color=blue]
              >
              > "mimages" <mimages@NOSPAM spvision.com> wrote in message
              > news:9VAcb.2477 1$Ci5.563011@tw ister.tampabay. rr.com...[color=green]
              > > Can someone tell me how to parse part of a string? I can use the[/color]
              > following:[color=green]
              > >
              > > <?php
              > > $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url);
              > > echo $text;
              > > ?>
              > >
              > > to get this result:
              > >
              > > "Your currently at /test.php "
              > >
              > > I just want to get "test.php " without the dash. I also need to parse[/color][/color]
              out[color=blue][color=green]
              > > parts of other strings. I know how to use Mid(), Left(), and Right() in[/color]
              > VB,[color=green]
              > > but no clue for PHP.
              > >
              > > Thanks in advance for the assistance.[/color]
              >
              > <?php
              >
              > $text = basename($_SERV ER['PHP_SELF']);
              > echo $text;
              >
              > ?>
              >
              >
              >
              >[/color]


              Comment

              • mimages

                #8
                Re: Parse part of string (mid string function ?)

                Thanks for all the graet responses. Time to get to work trying them.


                "David Gillen" <Belial@RedBric k.DCU.IE> wrote in message
                news:slrnbn5v34 .b53.Belial@car bon.redbrick.dc u.ie...[color=blue]
                > An noise sounding like Ian.H said:[color=green]
                > > On Thu, 25 Sep 2003 14:36:53 +0100, Geoff Berrow wrote:
                > >[color=darkred]
                > >> I noticed that Message-ID:
                > >> <9VAcb.24771$Ci 5.563011@twiste r.tampabay.rr.c om> from mimages contained
                > >> the following:
                > >>
                > >>> <?php
                > >>> $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url); echo
                > >>> $text;
                > >>>?>
                > >>>
                > >>>to get this result:
                > >>>
                > >>> "Your currently at /test.php "
                > >>>
                > >>>I just want to get "test.php " without the dash.
                > >>
                > >> <?php
                > >> $text = str_replace("/","","$_SER VER[PHP_SELF]");
                > >> echo $text;
                > >> ?>[/color]
                > >
                > >
                > > $text = array_pop(split ('/', $_SERVER['PHP_SELF']));
                > > echo $text;
                > >
                > >
                > > Just as another example.. although not tested for efficiency =)
                > >[/color]
                > You didn't test your code works so as to answer more questions, thus[/color]
                improving[color=blue]
                > your efficiency
                >
                > or
                > You didn't test the speed your code ran an vs the speed of the other to[/color]
                see[color=blue]
                > which was more efficient
                >
                > ??????
                >
                > Dave.
                > --
                >
                > I'm a dead man, and buggered to boot!
                >
                >[/color]


                Comment

                • mimages

                  #9
                  Re: Parse part of string (mid string function ?)

                  Yup, sure enough, this is what I was looking for.

                  Thanks!


                  "mimages" <mimages@NOSPAM spvision.com> wrote in message
                  news:BfHcb.2708 0$Ci5.602035@tw ister.tampabay. rr.com...[color=blue]
                  > Wow, basename, I don't think I'd have thought of this one. I'll try it.
                  > Thanks!
                  >
                  > "medi" <medi@banjaluka .com> wrote in message
                  > news:bkuq06$elk $1@news.teol.ne t...[color=green]
                  > >
                  > > "mimages" <mimages@NOSPAM spvision.com> wrote in message
                  > > news:9VAcb.2477 1$Ci5.563011@tw ister.tampabay. rr.com...[color=darkred]
                  > > > Can someone tell me how to parse part of a string? I can use the[/color]
                  > > following:[color=darkred]
                  > > >
                  > > > <?php
                  > > > $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url);
                  > > > echo $text;
                  > > > ?>
                  > > >
                  > > > to get this result:
                  > > >
                  > > > "Your currently at /test.php "
                  > > >
                  > > > I just want to get "test.php " without the dash. I also need to parse[/color][/color]
                  > out[color=green][color=darkred]
                  > > > parts of other strings. I know how to use Mid(), Left(), and Right()[/color][/color][/color]
                  in[color=blue][color=green]
                  > > VB,[color=darkred]
                  > > > but no clue for PHP.
                  > > >
                  > > > Thanks in advance for the assistance.[/color]
                  > >
                  > > <?php
                  > >
                  > > $text = basename($_SERV ER['PHP_SELF']);
                  > > echo $text;
                  > >
                  > > ?>
                  > >
                  > >
                  > >
                  > >[/color]
                  >
                  >
                  >[/color]


                  Comment

                  Working...