mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
- Layout and whitespace
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@132064 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
8b2c010b4f
commit
9d8e216f95
7 changed files with 173 additions and 156 deletions
|
@ -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="pcre.pattern.modifiers">
|
||||
<refnamediv>
|
||||
|
@ -48,8 +48,8 @@
|
|||
setting this modifier has no effect.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><emphasis>s</emphasis> (PCRE_DOTALL)</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
|
@ -61,8 +61,8 @@
|
|||
modifier.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><emphasis>x</emphasis> (PCRE_EXTENDED)</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
|
@ -79,8 +79,8 @@
|
|||
subpattern.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><emphasis>e</emphasis></term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
|
@ -89,18 +89,18 @@
|
|||
replacement string, evaluates it as PHP code, and uses the
|
||||
result for replacing the search string.
|
||||
</simpara>
|
||||
<simpara>
|
||||
<para>
|
||||
Only <function>preg_replace</function> uses this modifier;
|
||||
it is ignored by other PCRE functions.
|
||||
</simpara>
|
||||
<note>
|
||||
<simpara>
|
||||
This modifier was not available in PHP3.
|
||||
</simpara>
|
||||
</note>
|
||||
<note>
|
||||
<simpara>
|
||||
This modifier was not available in PHP3.
|
||||
</simpara>
|
||||
</note>
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><emphasis>A</emphasis> (PCRE_ANCHORED)</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
|
|
|
@ -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-all">
|
||||
<refnamediv>
|
||||
|
@ -38,6 +38,8 @@
|
|||
Orders results so that $matches[0] is an array of full
|
||||
pattern matches, $matches[1] is an array of strings matched by
|
||||
the first parenthesized subpattern, and so on.
|
||||
</para>
|
||||
<para>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
|
@ -52,12 +54,14 @@ print $out[1][0].", ".$out[1][1]."\n";
|
|||
</programlisting>
|
||||
<para>
|
||||
This example will produce:
|
||||
<screen>
|
||||
</para>
|
||||
<screen role="html">
|
||||
<![CDATA[
|
||||
<b>example: </b>, <div align=left>this is a test</div>
|
||||
example: , this is a test
|
||||
]]>
|
||||
</screen>
|
||||
</screen>
|
||||
<para>
|
||||
So, $out[0] contains array of strings that matched full pattern,
|
||||
and $out[1] contains array of strings enclosed by tags.
|
||||
</para>
|
||||
|
@ -84,16 +88,18 @@ print $out[1][0].", ".$out[1][1]."\n";
|
|||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
This example will produce:
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<para>
|
||||
This example will produce:
|
||||
</para>
|
||||
<screen role="html">
|
||||
<![CDATA[
|
||||
<b>example: </b>, example:
|
||||
<div align=left>this is a test</div>, this is a test
|
||||
]]>
|
||||
</programlisting>
|
||||
</screen>
|
||||
</informalexample>
|
||||
</para>
|
||||
<para>
|
||||
In this case, $matches[0] is the first set of matches, and
|
||||
$matches[0][0] has text matched by full pattern, $matches[0][1]
|
||||
has text matched by first subpattern and so on. Similarly,
|
||||
|
@ -160,9 +166,10 @@ for ($i=0; $i< count($matches[0]); $i++) {
|
|||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
This example will produce:
|
||||
<programlisting>
|
||||
<para>
|
||||
This example will produce:
|
||||
</para>
|
||||
<screen role="html">
|
||||
<![CDATA[
|
||||
matched: <b>bold text</b>
|
||||
part 1: <b>
|
||||
|
@ -174,7 +181,8 @@ part 1: <a href=howdy.html>
|
|||
part 2: click me
|
||||
part 3: </a>
|
||||
]]>
|
||||
</programlisting>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
<simpara>
|
||||
See also <function>preg_match</function>,
|
||||
|
|
|
@ -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-match">
|
||||
<refnamediv>
|
||||
|
@ -60,12 +60,14 @@
|
|||
<title>Find the string of text "php"</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// 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 {
|
||||
print "A match was not found.";
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -73,6 +75,7 @@ if (preg_match ("/php/i", "PHP is the web scripting language of choice.")) {
|
|||
<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"
|
||||
if (preg_match ("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
|
||||
|
@ -85,6 +88,7 @@ if (preg_match ("/\bweb\b/i", "PHP is the website scripting language of choice."
|
|||
} else {
|
||||
print "A match was not found.";
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -92,6 +96,7 @@ if (preg_match ("/\bweb\b/i", "PHP is the website scripting language of choice."
|
|||
<title>Getting the domain name out of a URL</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// get host name from URL
|
||||
preg_match("/^(http:\/\/)?([^\/]+)/i",
|
||||
"http://www.php.net/index.html", $matches);
|
||||
|
@ -99,16 +104,17 @@ $host = $matches[2];
|
|||
// get last two segments of host name
|
||||
preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$matches);
|
||||
echo "domain name is: ".$matches[0]."\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
This example will produce:
|
||||
<screen>
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
domain name is: php.net
|
||||
]]>
|
||||
</screen>
|
||||
</para>
|
||||
</screen>
|
||||
</example>
|
||||
See also <function>preg_match_all</function>,
|
||||
<function>preg_replace</function>, and
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.preg-quote">
|
||||
<refnamediv>
|
||||
|
@ -27,11 +27,11 @@
|
|||
used delimiter.</para>
|
||||
<para>
|
||||
The special regular expression characters are:
|
||||
<screen>. \\ + * ? [ ^ ] $ ( ) { } = ! < > | :</screen>
|
||||
<literal>. \\ + * ? [ ^ ] $ ( ) { } = ! < > | :</literal>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title></title>
|
||||
<title><function>preg_quote</function> example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
$keywords = "$40 for a g3/400";
|
||||
|
@ -40,6 +40,8 @@ echo $keywords; // returns \$40 for a g3\/400
|
|||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Italicizing a word within some text</title>
|
||||
<programlisting role="php">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.47 -->
|
||||
<refentry id="function.preg-replace-callback">
|
||||
<refnamediv>
|
||||
|
@ -23,9 +23,9 @@
|
|||
matched elements in the subject string. The callback should return the
|
||||
replacement string.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>preg_replace_callback</function> example</title>
|
||||
<programlisting role='php'>
|
||||
<example>
|
||||
<title><function>preg_replace_callback</function> example</title>
|
||||
<programlisting role='php'>
|
||||
<![CDATA[
|
||||
<?php
|
||||
// this text was used in 2002
|
||||
|
@ -51,48 +51,49 @@
|
|||
// Last christmas was 12/24/2002
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
You'll often need the <parameter>callback</parameter> function
|
||||
for a <function>preg_replace_callback</function> in just one place.
|
||||
In this case you can use <function>create_function</function> to
|
||||
declare an anonymous function as callback within the call to
|
||||
<function>preg_replace_callback</function>. By doing it this way
|
||||
you have all information for the call in one place and do not
|
||||
clutter the function namespace with a callback functions name
|
||||
not used anywhere else.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>preg_replace_callback</function> and <function>create_function</function></title>
|
||||
<programlisting role='php'>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
You'll often need the <parameter>callback</parameter> function
|
||||
for a <function>preg_replace_callback</function> in just one place.
|
||||
In this case you can use <function>create_function</function> to
|
||||
declare an anonymous function as callback within the call to
|
||||
<function>preg_replace_callback</function>. By doing it this way
|
||||
you have all information for the call in one place and do not
|
||||
clutter the function namespace with a callback functions name
|
||||
not used anywhere else.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>preg_replace_callback</function> and <function>create_function</function></title>
|
||||
<programlisting role='php'>
|
||||
<![CDATA[
|
||||
<?php
|
||||
// a unix-style command line filter to convert uppercase
|
||||
// letters at the beginning of paragraphs to lowercase
|
||||
/* a unix-style command line filter to convert uppercase
|
||||
* letters at the beginning of paragraphs to lowercase */
|
||||
|
||||
$fp = fopen("php://stdin", "r") or die("can't read stdin");
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp);
|
||||
$line = preg_replace_callback(
|
||||
'|<p>\s*\w|',
|
||||
create_function(
|
||||
// single quotes are essential here,
|
||||
// or alternative escape all $ as \$
|
||||
'$matches',
|
||||
'return strtolower($matches[0]);'
|
||||
),
|
||||
$line
|
||||
);
|
||||
echo $line;
|
||||
}
|
||||
fclose($fp);
|
||||
$fp = fopen("php://stdin", "r") or die("can't read stdin");
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp);
|
||||
$line = preg_replace_callback(
|
||||
'|<p>\s*\w|',
|
||||
create_function(
|
||||
// single quotes are essential here,
|
||||
// or alternative escape all $ as \$
|
||||
'$matches',
|
||||
'return strtolower($matches[0]);'
|
||||
),
|
||||
$line
|
||||
);
|
||||
echo $line;
|
||||
}
|
||||
fclose($fp);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
See also <function>preg_replace</function>, <function>create_function</function>.
|
||||
See also <function>preg_replace</function>,
|
||||
<function>create_function</function>.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.preg-replace">
|
||||
<refnamediv>
|
||||
|
@ -34,22 +34,22 @@
|
|||
<literal>\\0</literal> or <literal>$0</literal> refers to the text matched
|
||||
by the whole pattern. Opening parentheses are counted from left to right
|
||||
(starting from 1) to obtain the number of the capturing subpattern.
|
||||
<note>
|
||||
<para>
|
||||
When working with a replacement pattern where a backreference is immediately
|
||||
followed by another number (i.e.: placing a literal number immediately
|
||||
after a matched pattern), you cannot use the familiar <literal>\\1</literal>
|
||||
notation for your backreference. <literal>\\11</literal>, for example,
|
||||
would confuse <function>preg_replace</function> since it does not know whether
|
||||
you want the <literal>\\1</literal> backreference followed by a literal <literal>1</literal>,
|
||||
or the <literal>\\11</literal> backreference followed by nothing. In this case
|
||||
the solution is to use <literal>\${1}1</literal>. This creates an
|
||||
isolated <literal>$1</literal> backreference, leaving the <literal>1</literal>
|
||||
as a literal.
|
||||
</para>
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
When working with a replacement pattern where a backreference is immediately
|
||||
followed by another number (i.e.: placing a literal number immediately
|
||||
after a matched pattern), you cannot use the familiar <literal>\\1</literal>
|
||||
notation for your backreference. <literal>\\11</literal>, for example,
|
||||
would confuse <function>preg_replace</function> since it does not know whether
|
||||
you want the <literal>\\1</literal> backreference followed by a literal <literal>1</literal>,
|
||||
or the <literal>\\11</literal> backreference followed by nothing. In this case
|
||||
the solution is to use <literal>\${1}1</literal>. This creates an
|
||||
isolated <literal>$1</literal> backreference, leaving the <literal>1</literal>
|
||||
as a literal.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Using backreferences followed by numeric literals.</title>
|
||||
<title>Using backreferences followed by numeric literals</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
@ -76,22 +76,17 @@ April1,2003
|
|||
</para>
|
||||
<para>
|
||||
Every parameter to <function>preg_replace</function> (except
|
||||
<parameter>limit</parameter>) can be an array.
|
||||
<parameter>limit</parameter>) can be an array. 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>
|
||||
<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">
|
||||
|
@ -143,63 +138,71 @@ The slow black bear jumped over the lazy dog.
|
|||
as well.
|
||||
</para>
|
||||
<para>
|
||||
If <parameter>pattern</parameter> and
|
||||
<parameter>replacement</parameter> are arrays, then
|
||||
<function>preg_replace</function> takes a value from each array
|
||||
and uses them to do search and replace on
|
||||
<parameter>subject</parameter>. If
|
||||
<parameter>replacement</parameter> has fewer values than
|
||||
<parameter>pattern</parameter>, then empty string is used for the
|
||||
rest of replacement values. If <parameter>pattern </parameter>
|
||||
is an array and <parameter>replacement</parameter> is a string,
|
||||
then this replacement string is used for every value of
|
||||
<parameter>pattern</parameter>. The converse would not make
|
||||
sense, though.
|
||||
If <parameter>pattern</parameter> and <parameter>replacement</parameter>
|
||||
are arrays, then <function>preg_replace</function> takes a value from
|
||||
each array and uses them to do search and replace on
|
||||
<parameter>subject</parameter>. If <parameter>replacement</parameter>
|
||||
has fewer values than <parameter>pattern</parameter>, then empty string
|
||||
is used for the rest of replacement values. If <parameter>pattern
|
||||
</parameter> is an array and <parameter>replacement</parameter> is a
|
||||
string, then this replacement string is used for every value of
|
||||
<parameter>pattern</parameter>. The converse would not make sense,
|
||||
though.
|
||||
</para>
|
||||
<para>
|
||||
<literal>/e</literal> modifier makes
|
||||
<function>preg_replace</function> treat the
|
||||
<parameter>replacement</parameter> parameter as PHP code after
|
||||
the appropriate references substitution is done. Tip: make sure
|
||||
that <parameter>replacement</parameter> constitutes a valid PHP
|
||||
code string, otherwise PHP will complain about a parse error at
|
||||
the line containing <function>preg_replace</function>.
|
||||
<literal>/e</literal> modifier makes <function>preg_replace</function>
|
||||
treat the <parameter>replacement</parameter> parameter as PHP code after
|
||||
the appropriate references substitution is done. Tip: make sure that
|
||||
<parameter>replacement</parameter> constitutes a valid PHP code string,
|
||||
otherwise PHP will complain about a parse error at the line containing
|
||||
<function>preg_replace</function>.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Replacing several values</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
<?php
|
||||
$patterns = array ("/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/",
|
||||
"/^\s*{(\w+)}\s*=/");
|
||||
$replace = array ("\\3/\\4/\\1\\2", "$\\1 =");
|
||||
print preg_replace ($patterns, $replace, "{startDate} = 1999-5-27");
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
This example will produce:
|
||||
<programlisting>
|
||||
<para>
|
||||
This example will produce:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
$startDate = 5/27/1999
|
||||
]]>
|
||||
</programlisting>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Using /e modifier</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
preg_replace ("/(<\/?)(\w+)([^>]*>)/e",
|
||||
"'\\1'.strtoupper('\\2').'\\3'",
|
||||
$html_body);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
This would capitalize all HTML tags in the input text.
|
||||
</para>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Convert HTML to text</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// $document should contain an HTML document.
|
||||
// This will remove HTML tags, javascript sections
|
||||
// and white space. It will also convert some
|
||||
|
@ -234,6 +237,7 @@ $replace = array ("",
|
|||
"chr(\\1)");
|
||||
|
||||
$text = preg_replace ($search, $replace, $document);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.preg-split">
|
||||
<refnamediv>
|
||||
|
@ -66,44 +66,44 @@
|
|||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title><function>preg_split</function> example : Get the parts of a search string</title>
|
||||
<programlisting role="php">
|
||||
<para>
|
||||
<example>
|
||||
<title><function>preg_split</function> example : Get the parts of a search string</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
// split the phrase by any number of commas or space characters,
|
||||
// which include " ", \r, \t, \n and \f
|
||||
$keywords = preg_split ("/[\s,]+/", "hypertext language, programming");
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Splitting a string into component characters</title>
|
||||
<programlisting role="php">
|
||||
<example>
|
||||
<title>Splitting a string into component characters</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
$str = 'string';
|
||||
$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
|
||||
print_r($chars);
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Splitting a string into matches and their offsets</title>
|
||||
<programlisting role="php">
|
||||
<example>
|
||||
<title>Splitting a string into matches and their offsets</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
$str = 'hypertext language programming';
|
||||
$chars = preg_split('/ /', $str, -1, PREG_SPLIT_OFFSET_CAPTURE);
|
||||
print_r($chars);
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
will yield
|
||||
</para>
|
||||
<screen>
|
||||
</programlisting>
|
||||
<para>
|
||||
will yield:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Array
|
||||
(
|
||||
|
@ -127,8 +127,8 @@ Array
|
|||
|
||||
)
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
|
@ -136,15 +136,11 @@ Array
|
|||
</para>
|
||||
</note>
|
||||
<para>
|
||||
See also
|
||||
<function>spliti</function>,
|
||||
<function>split</function>,
|
||||
<function>implode</function>,
|
||||
<function>preg_match</function>,
|
||||
See also <function>spliti</function>, <function>split</function>,
|
||||
<function>implode</function>, <function>preg_match</function>,
|
||||
<function>preg_match_all</function>, and
|
||||
<function>preg_replace</function>.
|
||||
</para>
|
||||
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
|
|
Loading…
Reference in a new issue