Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17349

Re: help with preg_replace

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.php
Subject Re: help with preg_replace
Date 2017-04-13 14:51 +0200
Organization PointedEars Software (PES)
Message-ID <3058894.y9YRR5uL8U@PointedEars.de> (permalink)
References <ocnp48$1oei$1@gioia.aioe.org> <ocnpk2$vb5$1@softins.softins.co.uk>

Show all headers | View raw


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>

-- 
PointedEars
Zend Certified PHP Engineer <http://www.zend.com/en/yellow-pages/ZEND024953>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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