<HTML ><HEAD ><TITLE >Regular Expression Functions (POSIX Extended)</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="qdom_tree" HREF="function.qdom-tree.html"><LINK REL="NEXT" TITLE="ereg_replace" HREF="function.ereg-replace.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.qdom-tree.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.ereg-replace.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.regex" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >XC. Regular Expression Functions (POSIX Extended)</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN81899" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.intro" ></A >Introduction</H1 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > PHP also supports regular expressions using a Perl-compatible syntax using the <A HREF="ref.pcre.html" >PCRE functions</A >. Those functions support non-greedy matching, assertions, conditional subpatterns, and a number of other features not supported by the POSIX-extended regular expression syntax. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > These regular expression functions are not binary-safe. The <A HREF="ref.pcre.html" >PCRE functions</A > are. </P ></TD ></TR ></TABLE ></DIV ><P > Regular expressions are used for complex string manipulation in PHP. The functions that support regular expressions are: <P ></P ><UL ><LI ><P ><A HREF="function.ereg.html" ><B CLASS="function" >ereg()</B ></A ></P ></LI ><LI ><P ><A HREF="function.ereg-replace.html" ><B CLASS="function" >ereg_replace()</B ></A ></P ></LI ><LI ><P ><A HREF="function.eregi.html" ><B CLASS="function" >eregi()</B ></A ></P ></LI ><LI ><P ><A HREF="function.eregi-replace.html" ><B CLASS="function" >eregi_replace()</B ></A ></P ></LI ><LI ><P ><A HREF="function.split.html" ><B CLASS="function" >split()</B ></A ></P ></LI ><LI ><P ><A HREF="function.spliti.html" ><B CLASS="function" >spliti()</B ></A ></P ></LI ></UL > These functions all take a regular expression string as their first argument. PHP uses the POSIX extended regular expressions as defined by POSIX 1003.2. For a full description of POSIX regular expressions see the regex man pages included in the regex directory in the PHP distribution. It's in manpage format, so you'll want to do something along the lines of <B CLASS="command" >man /usr/local/src/regex/regex.7</B > in order to read it. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.requirements" ></A >Requirements</H1 ><P >No external libraries are needed to build this extension.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.installation" ></A >Installation</H1 ><P > To enable regexp support configure PHP <TT CLASS="option" >--with-regex[=TYPE]</TT >. TYPE can be one of system, apache, php. The default is to use php. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Do not change the TYPE unless you know what you are doing. </P ></BLOCKQUOTE ></DIV ><P > The windows version of <TT CLASS="literal" >PHP</TT > has built in support for this extension. You do not need to load any additional extension in order to use these functions.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.configuration" ></A >Runtime Configuration</H1 ><P >This extension has no configuration directives defined in <TT CLASS="filename" >php.ini</TT >.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.resources" ></A >Resource Types</H1 ><P >This extension has no resource types defined.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.constants" ></A >Predefined Constants</H1 ><P >This extension has no constants defined.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.examples" ></A >Examples</H1 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN81953" ></A ><P ><B >Example 1. Regular Expression Examples</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >ereg ("abc", $string); /* Returns true if"abc" is found anywhere in $string. */ ereg ("^abc", $string); /* Returns true if "abc"; is found at the beginning of $string. */ ereg ("abc$", $string); /* Returns true if "abc" is found at the end of $string. */ eregi ("(ozilla.[23]|MSIE.3)", $HTTP_USER_AGENT); /* Returns true if client browser is Netscape 2, 3 or MSIE 3. */ ereg ("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+)", $string,$regs); /* Places three space separated words into $regs[1], $regs[2] and $regs[3]. */ $string = ereg_replace ("^", "<br />", $string); /* Put a <br /> tag at the beginning of $string. */ $string = ereg_replace ("$", "<br />", $string); /* Put a <br />; tag at the end of $string. */ $string = ereg_replace ("\n", "", $string); /* Get rid of any newline characters in $string. */</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.seealso" ></A >See Also</H1 ><P > For regular expressions in Perl-compatible syntax have a look at the <A HREF="ref.pcre.html" >PCRE functions</A >. The simpler shell style wildcard pattern matching is provided by <A HREF="function.fnmatch.html" ><B CLASS="function" >fnmatch()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.ereg-replace.html" >ereg_replace</A > -- Replace regular expression</DT ><DT ><A HREF="function.ereg.html" >ereg</A > -- Regular expression match</DT ><DT ><A HREF="function.eregi-replace.html" >eregi_replace</A > -- replace regular expression case insensitive</DT ><DT ><A HREF="function.eregi.html" >eregi</A > -- case insensitive regular expression match</DT ><DT ><A HREF="function.split.html" >split</A > -- split string into array by regular expression</DT ><DT ><A HREF="function.spliti.html" >spliti</A > -- Split string into array by regular expression case insensitive </DT ><DT ><A HREF="function.sql-regcase.html" >sql_regcase</A > -- Make regular expression for case insensitive match </DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.qdom-tree.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.ereg-replace.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >qdom_tree</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >ereg_replace</TD ></TR ></TABLE ></DIV ></BODY ></HTML >