Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #17355
| From | bill <william@TechServSys.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: help with preg_replace |
| Date | 2017-04-14 11:13 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ocqouu$ipt$2@gioia.aioe.org> (permalink) |
| References | <ocnp48$1oei$1@gioia.aioe.org> <ocnpk2$vb5$1@softins.softins.co.uk> <3058894.y9YRR5uL8U@PointedEars.de> |
On 4/13/2017 8:51 AM, Thomas 'PointedEars' Lahn wrote:
> Tony Mountifield wrote:
>
>> $number = preg_replace("/\D/","",$phone);
>
> This should be
>
> $number = preg_replace('/\D/', '', $phone);
>
> Although it does not make a difference here, in general I recommend to
> consistently write string literals where no variable expansion is intended
> and where there are no straight apostrophes in the value, in single-quotes
> (straight apostrophes) in PHP (and similar programming languages).
>
> This approach also stops several escape sequences from being interpreted
> accidentally. For example, in PHP it makes a difference whether you write
> "\n" or '\n', and ā\nā is an escape sequence both in double-quoted string
> literals and Extended/Perl-Compatible Regular Expressions.
>
> <http://php.net/manual/en/language.types.string.php#language.types.string.syntax.single>
>
Thank you for the good suggestion.
--bill
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