Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #17354
| Path | csiph.com!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | bill <william@TechServSys.com> |
| Newsgroups | comp.lang.php |
| Subject | Re: help with preg_replace |
| Date | Fri, 14 Apr 2017 11:12:48 -0400 |
| Organization | Aioe.org NNTP Server |
| Lines | 30 |
| Message-ID | <ocqott$ipt$1@gioia.aioe.org> (permalink) |
| References | <ocnp48$1oei$1@gioia.aioe.org> <ocnpk2$vb5$1@softins.softins.co.uk> |
| NNTP-Posting-Host | 3qER3ivYp3VzEuZD7C/pcg.user.gioia.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.php:17354 |
Show key headers only | View raw
On 4/13/2017 8:06 AM, Tony Mountifield wrote:
> In article <ocnp48$1oei$1@gioia.aioe.org>,
> bill <william@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.
-bill
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
help with preg_replace bill <william@TechServSys.com> - 2017-04-13 07:57 -0400
Re: help with preg_replace tony@mountifield.org (Tony Mountifield) - 2017-04-13 12:06 +0000
Re: help with preg_replace Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-04-13 14:51 +0200
Re: help with preg_replace bill <william@TechServSys.com> - 2017-04-14 11:13 -0400
Re: help with preg_replace bill <william@TechServSys.com> - 2017-04-14 11:12 -0400
csiph-web