Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #17348
| Path | csiph.com!feeder.erje.net!1.eu.feeder.erje.net!news.albasani.net!.POSTED!softins.co.uk!not-for-mail |
|---|---|
| From | tony@mountifield.org (Tony Mountifield) |
| Newsgroups | comp.lang.php |
| Subject | Re: help with preg_replace |
| Date | Thu, 13 Apr 2017 12:06:27 +0000 (UTC) |
| Organization | Software Insight Ltd., Winchester, UK |
| Lines | 30 |
| Message-ID | <ocnpk2$vb5$1@softins.softins.co.uk> (permalink) |
| References | <ocnp48$1oei$1@gioia.aioe.org> |
| X-Trace | news.albasani.net 286UFkq0CNJ1P8sPBw38GKepeUfpYAJ677df7KVAOrvOv3P4zSuCouLPK6iDHnsZBDHBDrzPyDkbcfoaSwsNdA== |
| NNTP-Posting-Date | Thu, 13 Apr 2017 12:06:29 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="IGw7XDhz71hoXx1QEayroAYuJO87UCn7thcoyXE8mGMXuBdMA2vfBh2l7fRqIqE6ttsboljZqjuGjgdRobiZpTFxXe0FDKIlqhRJpaGk+49Ml9pFrxzAF2FSxBCnQFnh"; mail-complaints-to="abuse@albasani.net" |
| Originator | tony@softins.co.uk () |
| X-Newsreader | trn 4.0-test77 (Sep 1, 2010) |
| Cancel-Lock | sha1:mhKuVuss3ED+qboqr5rl0Bi5NyM= |
| Xref | csiph.com comp.lang.php:17348 |
Show key headers only | View raw
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
--
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org
Back to comp.lang.php | Previous | Next — Previous in thread | Next 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