1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
<reference id="ref.regex">
<title>Regular expression functions</title>
<titleabbrev>Regexps</titleabbrev>
<refentry id="function.ereg">
<refnamediv>
<refname>ereg</refname>
<refpurpose>regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>ereg</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>array <parameter><optional>regs</optional></parameter></paramdef>
</funcsynopsis>
<simpara>
Searchs <parameter>string</parameter> for matches to the regular expression
given in <parameter>pattern</parameter>.
<simpara>
If matches are found for parenthesized substrings of
<parameter>pattern</parameter> and the function is called with
the third argument <parameter>regs</parameter>, the matches will
be stored in the elements of
<parameter>regs</parameter>. $regs[1] will contain the substring
which starts at the first left parenthesis; $regs[2] will contain the
substring starting at the second, and so on. $regs[0] will
contain a copy of <parameter>string</parameter>.
<para>
Searching is case sensitive.
<para>
Returns true if a match for pattern was found in string, or false
if no matches were found or an error occurred.
<para>
The following code snippet takes a date in ISO format (YYYY-MM-DD)
and prints it in DD.MM.YYYY format:
<example>
<title>ereg() example</title>
<programlisting>
if ( ereg( "([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs ) ) {
echo "$regs[3].$regs[2].$regs[1]";
} else {
echo "Invalid date format: $date";
}
</programlisting></example>
<para>
See also <function>eregi</function>, <function>ereg_replace</function>, and <function>eregi_replace</function>.
</refsect1>
</refentry>
<refentry id="function.ereg-replace">
<refnamediv>
<refname>ereg_replace</refname>
<refpurpose>replace regular expression</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>ereg_replace</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>replacement</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcsynopsis>
<para>
This function scans <parameter>string</parameter> for matches to
<parameter>pattern</parameter>, then replaces the matched text
with <parameter>replacement</parameter>.
<para>
If <parameter>pattern</parameter> contains parenthesized
substrings, <parameter>replacement</parameter> may contain
substrings of the form
<literal>\\<replaceable>digit</replaceable></literal>, which will
be replaced by the text matching the digit'th parenthesized
substring; <literal>\\0</literal> will produce the entire
contents of string. Up to nine substrings may be used.
Parentheses may be nested, in which case they are counted by the
opening parenthesis. For example, the following code snippet
prints "This was a test" three times:
<example>
<title>ereg_replace() example</title>
<programlisting>
$string = "This is a test";
echo ereg_replace( " is", " was", $string );
echo ereg_replace( "( )is", "\\1was", $string );
echo ereg_replace( "(( )is)", "\\2was", $string );
</programlisting></example>
See also <function>ereg</function>, <function>eregi</function>, and <function>eregi_replace</function>.
</refsect1>
</refentry>
<refentry id="function.eregi">
<refnamediv>
<refname>eregi</refname>
<refpurpose>case insensitive regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>eregi</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>array <parameter><optional>regs</optional></parameter></paramdef>
</funcsynopsis>
<para>
This function is identical to <function>ereg</function> save that this ignores
case distinction when matching alphabetic characters.
<para>
See also <function>ereg</function>, <function>ereg_replace</function>, and <function>eregi_replace</function>.
</refsect1>
</refentry>
<refentry id="function.eregi-replace">
<refnamediv>
<refname>eregi_replace</refname>
<refpurpose>replace regular expression case insensitive</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>eregi_replace</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>replacement</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcsynopsis>
<para>
This function is identical to <function>ereg_replace</function> save that
this ignores case distinction when matching alphabetic characters.
<para>
See also <function>ereg</function>, <function>eregi</function>, and <function>ereg_replace</function>.
</refsect1>
</refentry>
<refentry id="function.split">
<refnamediv>
<refname>split</refname>
<refpurpose>split string into array by regular expression</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>array <function>split</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int <parameter><optional>limit</optional></parameter></paramdef>
</funcsynopsis>
<para>
Returns an array of strings, each of which is a substring of
string formed by splitting it on boundaries formed
by <parameter>pattern</parameter>. If an error occurs, returns false.
<para>
To get the first five fields from a line from
<filename>/etc/passwd</filename>:
<example>
<title>split() example</title>
<programlisting>
$passwd_list = split( ":", $passwd_line, 5 );
</programlisting></example>
</refsect1>
</refentry>
<refentry id="function.sql-regcase">
<refnamediv>
<refname>sql_regcase</refname>
<refpurpose>make regular expression for case insensitive match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>sql_regcase</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcsynopsis>
<para>
Returns a valid regular expression which will match <parameter>string</parameter>,
ignoring case. This expression is <parameter>string</parameter> with each character
converted to a bracket expression; this bracket expression
contains that character's uppercase and lowercase form if
applicable, otherwise it contains the original character
twice.
<example>
<title>sql_regcase() example</title>
<programlisting>
echo sql_regcase( "Foo bar" );
</programlisting></example>
prints <screen>[Ff][Oo][Oo][ ][Bb][Aa][Rr]</screen>.
<para>
This can be used to achieve case insensitive pattern matching in
products which support only case sensitive regular expressions.
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
|