LearnerId:

Php Programming


Content List

Skip Navigation Links.
Collapse Total Week Wise ContentTotal Week Wise Content
Collapse Week1Week1
Collapse Week2Week2
Collapse Week3Week3
Collapse Week4Week4
Collapse Week5 : DataBaseWeek5 : DataBase
Collapse Week6:Week6:
Collapse Week 7: ProjectWeek 7: Project

PHP Regular Expression:-

Regular expression charecters का sequence या pattern नहीं होता है बल्कि यह हमे pre matching functionality provide करता है । हम regular expression का use करके particular string किसी दूसरी string को search कर सकते है, refresh कर सकते हैँ, या उन्हें तोड़ (split) कर सकते है । PHP 2 type के regular expression provide करती है जो निम्न है

  • Posix regular expression
  • PERL style regular expression

Posix regular expression:-posix regular expression वो होते है जो string, charecters, expression तथा arithmetic expression में pettern matching के लिये use आता है

For Example:- ereg_replace() function का use specify string को किसी special pattern द्वारा search कर उसको किसी दूसरी string से replace करना है इसका syntax निम्न है
Syntax :- string ereg_replace (string pattern, string replacement, string originalstring);


Figure:-1 Use Of ereg_replace() function

उपरोक्त code को जब हम browser पर run कराते है तो following Output produce होता है -
Output


Figure:-2 ereg_replace() function Output


currently posix style regular expression हमें 7 function provide करता है जो कि निम्न है

Function Description
ereg() The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise.
ereg_replace() The ereg_replace() function searches for string specified by pattern and replaces pattern with replacement if found.
eregi() The eregi() function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive.
eregi_replace() The eregi_replace() function operates exactly like ereg_replace(), except that the search for pattern in string is not case sensitive.
split() The split() function will divide a string into various elements, the boundaries of each element based on the occurrence of pattern in string.
spliti() The spliti() function operates exactly in the same manner as its sibling split(), except that it is not case sensitive.
sql_regcase() The sql_regcase() function can be thought of as a utility function, converting each character in the input parameter string into a bracketed expression containing two characters.

PERL style regular expression:- PHP offers following functions for searching strings using Perl-compatible regular expressions −

Function Description
preg_match() The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise.
preg_match_all() The preg_match_all() function matches all occurrences of pattern in string.
preg_replace() The preg_replace() function operates just like ereg_replace(), except that regular expressions can be used in the pattern and replacement input parameters.
preg_split() The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.
preg_grep() The preg_grep() function searches all elements of input_array, returning all elements matching the regexp pattern.
preg_ quote() Quote regular expression characters
left right