Re: note 9102 added to ereg_replace

From: Date: Mon, 16 Oct 2000 23:35:05 +0000
Subject: Re: note 9102 added to ereg_replace
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-6541@lists.php.net to get a copy of this message
mrhattyhat@yahoo.com writes: > Can someone explain why a literal backslash (which should be > represented in RegEx by \\) has to be represented by \\\\ in PHP (at > least in ereg_replace)? It seems sort of silly. > > http://www.php.net/manual/function.ereg-replace.php This note has been deleted; the forum for questions and answers is the mailing list, at php-general@lists.php.net. Go to http://www.php.net/support.php to sign up. Please make sure to read the instructions at http://www.php.net/manual/add-note.php before adding another note. In answer to your question, you'll only need to double-escape things if you're using double-quoted strings. Since PHP interpolates double-quoted strings, you need one escape to prevent PHP from parsing it. Then, after PHP has parsed the string and passed it to the regex engine, the engine parses it again--requiring the second escape. -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.notes (#6541) next »