WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Regular Expressions
Categories : PHP, Regexps Click here to Update Your Picture
Pradeep Mamgain
Date : Jul 16th 2002
Grade : 1 of 5 (graded 2 times)
Viewed : 4450
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Pradeep Mamgain
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Regular expressions are used for complex string manipulation in PHP.A regular
expression is a pattern that is matched against a subject string from left to right.

To interpret data you need regular expressions. In PHP regular expessions are
accessed through functions.
ereg()
ereg_replace()
eregi()
eregi_replace()
split()
spliti()
sql_regcase()

Meta Characters
===============
Part of a pattern that is in square brackets is called a "character class". In a
character class the only meta- characters are:

\ general escape character
^ negate the class, but only if the first character
- indicates character range
] terminates the character class

Outside square brackets, the meta-characters are as follows:
\ general escape character
^ start of line
$ end of line
. match any character except newline (by default)
[ start character class definition
] end character class definition
| start of alternative branch
( start subpattern
) end subpattern
? extends the meaning of (, also 0 or 1 quantifier, also quantifier minimizer
* 0 or more quantifier
+ 1 or more quantifier
{ start min/max quantifier
} end min/max quantifier


It is always safe to precede a non-alphameric with "\". It can also be used with non
printable chracters. Like ...
/a alarm, /cchar control + char where char is the character
/e escape,/f form feed, /n newline, /r carrige return
/t tab

Backslash can also be used for specifying generic charac- ter types:
\d - any decimal digit
\D - any character that is not decimal digit.
\s - any whitespace character
\S - any character that is not white space.
\w - any word character
\W - any non word character.

Matching Strings
================
While matching strings two meta-character are widely used $(dollar sign) and ^
(circumflex) sign. $ sign tells PHP to match the string at the end of the string,
the ^sign will match any pattren at the beginning of the string.

Expression ^liquidpulse would match the following ..


liquidpulse is one of the best web resource
liquidpulse is best php resource

Expression resource$ will also match the above lines.

Matching Escape Sequences
=========================
Consider expression jerrett\ntaylor. Criteria (jerret, linebreak,taylor) would match
followings

liquidpulse
taylor is lastname of Jerrett

Character Classes
=================
[a-zA-z] Match any letter
[a-zA-Z0-9] Match any letter or number
[ \t\n\v\r\f] Match any whitespace character
[0-9\.\-] Match any number, minus sign or period

To negate the character class, you can use the ^ meta character but only when ^ is
the very first character inside the brackets like [^a-z]

More then one Occurance of a Character
Usee {} metacharacter
[A-Z]{5} Number 5 tells PHP to match a string that contains five uppercase
characters in
a row.To match a range of characters specify lower and upper limits like {1,6}

The * quantifier will match zero or more occurrences of a character and the +
quantiier
will match one or more occurences of a character. [a-z]* will match zero or more
occurences of lowercase letters in a string.

Optional Matches
================
? meta-character is used for this purpose
[a-z]{4}? would optionally match four occurences of any lowercase characters so
following would be valid.
NETRPX
jerrett taylor
LP

Predefined character Classes
============================
[[:alnum:]] All alphanumeric characters [a-zA-Z09]
[[:alpha:]] All alphabatic characters [a-Z]
[[:blank:]] Tab and Space
[[:cntrl:]] All the control characters
[[:digit:]] All decimal digits [0-9]
[[:graph:]] All printable characters except space
[[:lower:]] All lowecase characters
[[:print:]] All printable characters
[[:punct:]] Punctuation marks [\.,;:-]
[[:space:]] All whitespace characters
[[:upper:]] All the upercase letters [A-Z]
[[:xdigit:]] The set of hexadecimal digits

To negate the class make sure that you put ^ inside the first bracket.
[^[:digit:]]

The pipe (|) Delimiter
Here is an example (liquidpulse|netrpx) , PHP will match either liquidpulse or
netrpx.



How to build a search query for any N number of words in a search string
Categories : PHP, Regexps, Search Engines, Search
validateEmail 2.0 - upgraded version of the old validateEmail function used to validate email addresses via SMTP and regex.
Categories : Email, Regexps, PHP
Newbie Notes #7 - Ridiculous regex
Categories : PHP, Beginner Guides, Regexps
PHP Youtube Downloader - This is a set of PHP functions that can be used to download movies from Youtube.com.
Categories : PHP, CURL, Regexps
email validator check checker email e-mail email address
Categories : PHP, Email, Regexps
PHP Script to find url links in a page
Categories : PHP, URLs, Regexps, Arrays
String Replacement and speed consideration
Categories : PHP, Strings, Regexps
Massreplace
Categories : Filesystem, Regexps, Strings, PHP
FormChecker Package - validate any data via classes and patterns.
Categories : PHP, Form Processing, PHP Classes, Regexps
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
How to strip non-alpha characters from a string
Categories : Regexps, PHP
Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP
Categories : PHP, HTTP, Regexps
Avoiding or Detecting high bit characters in a string. Useful when you want to create a valid RSS feed
Categories : PHP, Strings, Unicode, Regexps, Rich Site Summary (RSS)
Extract keywords from a string having words in " " count as one string.
Categories : PHP, Strings, Regexps, Search
YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL