cvs: php-bugs-web /include functions.inc phpdoc/en/reference/pcre/functions preg-replace.xml

From: Date: Thu, 23 Jan 2003 01:04:50 +0000
Subject: cvs: php-bugs-web /include functions.inc phpdoc/en/reference/pcre/functions preg-replace.xml
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-15267@lists.php.net to get a copy of this message
sniper Wed Jan 22 20:04:50 2003 EDT Modified files: /php-bugs-web/include functions.inc /phpdoc/en/reference/pcre/functions preg-replace.xml Log: Require a non-empty password. Index: php-bugs-web/include/functions.inc diff -u php-bugs-web/include/functions.inc:1.62 php-bugs-web/include/functions.inc:1.63 --- php-bugs-web/include/functions.inc:1.62 Sun Jan 19 06:54:28 2003 +++ php-bugs-web/include/functions.inc Wed Jan 22 20:04:49 2003 @@ -388,10 +388,10 @@ } /* validate an incoming bug report */ -function incoming_details_are_valid($in,$initial=0) +function incoming_details_are_valid ($in, $initial=0) { $errors = array(); - if(!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i",$in['email'])) { + if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i",$in['email'])) { $errors[] = "Please provide a valid email address."; } @@ -399,23 +399,23 @@ $errors[] = "Please select an appropriate bug type."; } - if ($in['php_version'] == 'earlier') { + if (isset($in['php_version']) && $in['php_version'] == 'earlier') { $errors[] = "Please select a valid PHP version. If your PHP version is too old, please upgrade first and see if the problem has not already been fixed."; } - if (!$in['php_version']) { + if (empty($in['php_version'])) { $errors[] = "Please select a valid PHP version."; } - if (!$in['sdesc']) { + if (empty($in['sdesc'])) { $errors[] = "You must supply a short description of the bug you are reporting."; } - if ($initial && !$in['ldesc']) { + if ($initial && empty($in['ldesc'])) { $errors[] = "You must supply a long description of the bug you are reporting."; } - if ($initial && !$in['passwd']) { + if ($initial && empty($in['passwd'])) { $errors[] = "You must supply a password for this bug report."; } Index: phpdoc/en/reference/pcre/functions/preg-replace.xml diff -u phpdoc/en/reference/pcre/functions/preg-replace.xml:1.4 phpdoc/en/reference/pcre/functions/preg-replace.xml:1.5 --- phpdoc/en/reference/pcre/functions/preg-replace.xml:1.4 Mon Jan 20 14:52:12 2003 +++ phpdoc/en/reference/pcre/functions/preg-replace.xml Wed Jan 22 20:04:49 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 --> <refentry id="function.preg-replace"> <refnamediv> @@ -77,6 +77,64 @@ <para> Every parameter to <function>preg_replace</function> (except <parameter>limit</parameter>) can be an array. + </para> + <para> + <note> + <para> + When using arrays with <parameter>pattern</parameter> and + <parameter>replacement</parameter>, the keys are processed + in the order they appear in the array. This is + <emphasis>not necessarily</emphasis> the same as the numerical + index order. If you use indexes to identify which + <parameter>pattern</parameter> should be replaced by which + <parameter>replacement</parameter>, you should perform a + <function>ksort</function> on each array prior to calling + <function>preg_replace</function>. + </para> + </note> + <example> + <title>Using indexed arrays with <function>preg_replace</function></title> + <programlisting role="php"> +<![CDATA[ +<?php +$string = "The quick brown fox jumped over the lazy dog."; + +$patterns[0] = "/quick/"; +$patterns[1] = "/brown/"; +$patterns[2] = "/fox/"; + +$replacements[2] = "bear"; +$replacements[1] = "black"; +$replacements[0] = "slow"; + +print preg_replace($patterns, $replacements, $string); + +/* Output + ====== + +The bear black slow jumped over the lazy dog. + +*/ + +/* By ksorting patterns and replacements, + we should get what we wanted. */ + +ksort($patterns); +ksort($replacements); + +print preg_replace($patterns, $replacements, $string); + +/* Output + ====== + +The slow black bear jumped over the lazy dog. + +*/ + +?> +]]> + </programlisting> + </example> </para> <para> If <parameter>subject</parameter> is an array, then the search

« previous php.mirrors (#15267) next »