cut problem

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

    cut problem

    How can i cut the rest of a string, when i only know that it is
    closed with a , ?

    Example:

    $string = "kyo wa doyoubi desu kara,xxxxxxxxx xx ";

    $new = cut_it_right($s tring);

    ==> $new == "kyo wa doyoubi desu kara,";

  • Marcel

    #2
    Re: cut problem


    "Markus Stadler" <atlanx@gmx.d e> schreef in bericht
    news:bk758b$1k6 $1@online.de...[color=blue]
    > How can i cut the rest of a string, when i only know that it is
    > closed with a , ?
    >
    > Example:
    >
    > $string = "kyo wa doyoubi desu kara,xxxxxxxxx xx ";
    >
    > $new = cut_it_right($s tring);
    >
    > ==> $new == "kyo wa doyoubi desu kara,";
    >[/color]

    Try something like this:

    <?php

    # To find the last position of a
    $pos_last_a = strrpos($string ,"a");

    # cut string from start to last position of a
    $new = substr($string, 0,($pos_last_a+ 1));

    ?>

    Regards,

    marcel







    Comment

    • Markus Stadler

      #3
      Re: cut problem

      Marcel schrieb:
      [color=blue]
      > Try something like this:
      >
      > <?php
      >
      > # To find the last position of a
      > $pos_last_a = strrpos($string ,"a");
      >
      > # cut string from start to last position of a
      > $new = substr($string, 0,($pos_last_a+ 1));
      >
      > ?>
      >
      > Regards,
      > marcel[/color]

      Thank you.
      I have overseen the second r in strrpos()
      so i have only found strpos() in the doc :)


      Comment

      • Markus Stadler

        #4
        Re: cut problem

        Thank you, that was it.
        Markus

        Comment

        • Randell D.

          #5
          Re: cut problem


          "Markus Stadler" <atlanx@gmx.d e> wrote in message
          news:bk758b$1k6 $1@online.de...[color=blue]
          > How can i cut the rest of a string, when i only know that it is
          > closed with a , ?
          >
          > Example:
          >
          > $string = "kyo wa doyoubi desu kara,xxxxxxxxx xx ";
          >
          > $new = cut_it_right($s tring);
          >
          > ==> $new == "kyo wa doyoubi desu kara,";
          >[/color]

          You could try something like

          $string = eregi_replace(" ,.*", "", $string); // first arg is comma dot
          asterix - second are two empty quotes

          I've not tested the above syntax but I believe it says to replace anything
          that follows immediately after the comma with nothing (the empty quotes).


          Comment

          Working...