I don't no which method suites perfect
to my req..

Req:- Need to trim a string, take off all the alphabets then retun the string.

do i need to use str_replace or preg_replace or some thing else?

    Probably preg_replace, 'cause if you wanna take all the alphabet characters out, you can just specify [a-zA-Z] instead of "abcdef...etc"

    Diego

      Thanks for your Quick reply !!

      $phone = preg_replace("/[a..zA..Z]/","", $phone);

      this fails and ineed to eleminate spaces
      and -, _ in the $phone..

      Appreciate your help !!

        I'm nowhere near an expert on preg_replace, so I'll let diego or someone else take care of that, but you could use str_replace to get rid of spaces and - on the phone.

        $phone = "555-643-8453";
        
        // get rid of spaces (if any)
        $phone = str_replace(" ", "", $phone);
        
        // get rid of dashes (if any)
        $phone = str_replace("-", "", $phone);

        Cristian

          The only thing I'm an expert at is knowing that I'm not an expert 🙂

          Anyway, try this:

          $phone = preg_replace('/[a-zA-Z-_\s]/', '', $phone);

          Diego

            10 days later
            Write a Reply...