derick Fri Jun 20 11:21:50 2003 EDT Modified files: /phpdoc/en/reference/pcre/functions preg-match.xml Log: - Distinguish between notes and tips - Use // for single line comments and /* // */ for multi line comments Index: phpdoc/en/reference/pcre/functions/preg-match.xml diff -u phpdoc/en/reference/pcre/functions/preg-match.xml:1.6 phpdoc/en/reference/pcre/functions/preg-match.xml:1.7 --- phpdoc/en/reference/pcre/functions/preg-match.xml:1.6 Fri Jun 20 11:10:41 2003 +++ phpdoc/en/reference/pcre/functions/preg-match.xml Fri Jun 20 11:21:50 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 --> <refentry id="function.preg-match"> <refnamediv> @@ -20,10 +20,11 @@ expression given in <parameter>pattern</parameter>. </para> <para> - If <parameter>matches</parameter> is provided, then it is filled - with the results of search. $matches[0] will contain the text that - matched the full pattern, $matches[1] will have the text that matched - the first captured parenthesized subpattern, and so on. + If <parameter>matches</parameter> is provided, then it is filled with the + results of search. <varname>$matches[0]</varname> will contain the text + that matched the full pattern, <varname>$matches[1]</varname> will have + the text that matched the first captured parenthesized subpattern, and so + on. </para> <para> <parameter>flags</parameter> can be the following flag: @@ -55,20 +56,21 @@ <parameter>subject</parameter>. <function>preg_match</function> returns &false; if an error occured. </para> - <note> + <tip> <para> Do not use <function>preg_match</function> if you only want to check if - one string is contained in another string. Use <function>strpos</function> - or <function>strstr</function> instead. + one string is contained in another string. Use + <function>strpos</function> or <function>strstr</function> instead as + they will be faster. </para> - </note> + </tip> <para> <example> <title>Find the string of text "php"</title> <programlisting role="php"> <![CDATA[ <?php -// the "i" after the pattern delimiter indicates a case-insensitive search +// The "i" after the pattern delimiter indicates a case-insensitive search if (preg_match ("/php/i", "PHP is the web scripting language of choice.")) { print "A match was found."; } else { @@ -78,18 +80,21 @@ ]]> </programlisting> </example> + </para> + <para> <example> - <title>find the word "web"</title> + <title>Find the word "web"</title> <programlisting role="php"> <![CDATA[ <?php -// the \b in the pattern indicates a word boundary, so only the distinct -// word "web" is matched, and not a word partial like "webbing" or "cobweb" +/* The \b in the pattern indicates a word boundary, so only the distinct + * word "web" is matched, and not a word partial like "webbing" or "cobweb" */ if (preg_match ("/\bweb\b/i", "PHP is the web scripting language of choice.")) { print "A match was found."; } else { print "A match was not found."; } + if (preg_match ("/\bweb\b/i", "PHP is the website scripting language of choice.")) { print "A match was found."; } else { @@ -99,6 +104,8 @@ ]]> </programlisting> </example> + </para> + <para> <example> <title>Getting the domain name out of a URL</title> <programlisting role="php"> @@ -106,11 +113,12 @@ <?php // get host name from URL preg_match("/^(http:\/\/)?([^\/]+)/i", -"http://www.php.net/index.html", $matches); + "http://www.php.net/index.html", $matches); $host = $matches[2]; + // get last two segments of host name -preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$matches); -echo "domain name is: ".$matches[0]."\n"; +preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches); +echo "domain name is: {$matches[0]}\n"; ?> ]]> </programlisting> @@ -123,6 +131,8 @@ ]]> </screen> </example> + </para> + <para> See also <function>preg_match_all</function>, <function>preg_replace</function>, and <function>preg_split</function>.
-- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php