<HTML ><HEAD ><TITLE >Regular expression functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="recode_file" HREF="function.recode-file.html"><LINK REL="NEXT" TITLE="ereg" HREF="function.ereg.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><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.recode-file.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.ereg.html" >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" >XLVI. Regular expression functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN24600" ></A ><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 ></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 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 1. Regular expression examples</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 ereg("abc",$string); 3 /* Returns true if "abc" 4 is found anywhere in $string. */ 5 6 ereg("^abc",$string); 7 /* Returns true if "abc" 8 is found at the beginning of $string. */ 9 10 ereg("abc$",$string); 11 /* Returns true if "abc" 12 is found at the end of $string. */ 13 14 eregi("(ozilla.[23]|MSIE.3)",$HTTP_USER_AGENT); 15 /* Returns true if client browser 16 is Netscape 2, 3 or MSIE 3. */ 17 18 ereg("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+)", 19 $string,$regs); 20 /* Places three space separated words 21 into $regs[1], $regs[2] and $regs[3]. */ 22 23 $string = ereg_replace("^","<BR>",$string); 24 /* Put a <BR> tag at the beginning of $string. */ 25 26 $string = ereg_replace("$","<BR>",$string); 27 /* Put a <BR> tag at the end of $string. */ 28 29 $string = ereg_replace("\n","",$string); 30 /* Get rid of any newline 31 characters in $string. */ 32 </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></P ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.ereg.html" >ereg</A > — regular expression match</DT ><DT ><A HREF="function.ereg-replace.html" >ereg_replace</A > — replace regular expression</DT ><DT ><A HREF="function.eregi.html" >eregi</A > — case insensitive regular expression match</DT ><DT ><A HREF="function.eregi-replace.html" >eregi_replace</A > — replace regular expression case insensitive</DT ><DT ><A HREF="function.split.html" >split</A > — split string into array by regular expression</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 WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.recode-file.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.ereg.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >recode_file</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >ereg</TD ></TR ></TABLE ></DIV ></BODY ></HTML >