On 4/13/2017 8:06 AM, Tony Mountifield wrote:
> In article <ocnp48$1oei$
1...@gioia.aioe.org>,
> bill <wil...@TechServSys.com> wrote:
>> I am trying to strip all non-numeric characters from a string.
>> This is my best guess, but it doesn't do anything to the input
>> string.
>>
>> $number =preg_replace("[^0-9]","",$phone);
>>
>> when $phone is '1a2bc34567890'
>>
>
> The pattern string needs to include delimiters within the string,
> so in your case, something like "/[^0-9]/".
>
> You can also use the specifier \D to mean non-digit:
>
> $phone = '1a2bc34567890';
> $number = preg_replace("/\D/","",$phone);
> echo "$phone => $number";
>
> Produces:
> 1a2bc34567890 => 1234567890
>
> Cheers
> Tony
>
Cheers indeed. Thank you for the explanation.