I got a array filled with strings.
What I want to do is remove the first three characters (numbers) of every string in the array.

The strings look like this:
010Boten
020Beelden
030Water

And the result should look like this
Boten
Beelden
Water

I think this should be very easy, but I can't find right commando's to get this working.

Arjen.

    There's a million ways of doing this. For string manipulation, I recommend regex in every case. Check [man]ereg_replace/man. To regex your way to freedom, try this:

    // below regex explained:
    // ^        begining of the line
    // [0-9]  characters in that range (numbers)
    // +        one or more of these (numbers)
    // ()        register, first () pair stored in \1
    // .         any character
    // *        any number of time (eg the rest of the line) 
    $str = ereg_replace('^[0-9]+(.*)', '\1', $str);
    

      Let's keep it simple.

      $rest = substr("abcdef", 3); // returns "def"

        I couldn't get it to work with 'ereg_replace'. Instead I tried 'preg_replace', wich replace text...

        I don't get the '[0-9]+(.*)' part of ereg_replace. Not even after looking in my PHP-handbook or at www.php.net. 😕
        Maybe someone could give some explanation?

        To get it to work, this is what I did:

        for ($i=0;$i<=9;$i++)
        {
        $search[$i]="'$i'";
        }

        $replace = "";

        $str_x = preg_replace($search, $replace, $str);

        so: "010aaa010" becomes "aaa", "020bbb020"becomes "bbb".

        But what I want is only the first three numbers to be removed.

        Help is appriciated.

        Arjen.

          Originally posted by Buddha443556
          Let's keep it simple.

          $rest = substr("abcdef", 3); // returns "def"

          Thanks! That did the job.

          This is what I made:

          for($i=0;$i<count($str);$i++)
          {
          $str_x[$i] = substr($str[$i],3);
          }

          Arjen.

            Write a Reply...