note 68594 added to ref.pcre

From: Date: Wed, 02 Aug 2006 22:11:44 +0000
Subject: note 68594 added to ref.pcre
Groups: php.notes 
Request: Send a blank email to php-notes+get-115494@lists.php.net to get a copy of this message
Here it is a simple PHP function that escapes a string to safely use it in a Regular Expression, very useful to include unknown strings in PCRE patterns: <?php function safe_preg($content) { $search = array('\\\\', '^', '$', '.', '[', ']', '|', '(', ')', '?', '*', '+', '{', '}'); $replace = array('\\\\\\\\', '\\^', '\\$', '\\.', '\\[', '\\]', '\\|', '\\(', '\\)', '\\?', '\\*', '\\+', '\\{', '\\}'); return str_replace($search, $replace, $content); } ?> ---- Server IP: 213.92.11.19 Probable Submitter: 151.25.62.243 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.pcre.php Edit -- https://master.php.net/note/edit/68594 Del: integrated -- https://master.php.net/note/delete/68594/integrated Del: useless -- https://master.php.net/note/delete/68594/useless Del: bad code -- https://master.php.net/note/delete/68594/bad+code Del: spam -- https://master.php.net/note/delete/68594/spam Del: non-english -- https://master.php.net/note/delete/68594/non-english Del: in docs -- https://master.php.net/note/delete/68594/in+docs Del: other reasons-- https://master.php.net/note/delete/68594 Reject -- https://master.php.net/note/reject/68594 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115494) next »