Php Regular Expressions
Regular expressions are nothing more than a sequence or pattern of characters it. They provide the foundation for pattern matching functionality.
Using regular expression you can search a particular string inside a string, you can replace one string by another string and you can split a string into many chunks.
ereg()
The ereg() function searches a string specified by string for a string specified by the pattern, returning true if the pattern is found, and false otherwise.
Example
<?php $date('Y-m-d'); if(ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})",$date,$regs)){ echo "$regs[3].$regs[2].$regs[1]"; }else{ echo "invalide date formate"; } // output 21.07.2019 ?>
ereg_replace()
The ereg_replace() functions search for the string specified by pattern and replaces the pattern with a replacement if found.
eregi()
The eregi() function searches throughout a string specified by the pattern for a string specified by string. the search is not case-sensitive.
Example
<?php if(eregi("z",$string)){ echo "'$string' contains a 'z' or 'Z'"; // output z contains a 'z' or 'Z' } ?>
ereg_replace()
The ereg_replace() function operates exactly like ereg_replace(), except that the search for pattern in a string is not case sensitive.
Example
<?php $string = "This is a cow"; echo ereg_replace("is","was",$string); //output This was a cow ?>
split()
The split() function will divide a string into various elements, the boundaries of each element based on the occurrence of pattern in a string.
Example
<?php $date = "04/30/1973"; list($month,$day,$year) = split('/',$date); echo 'Month :'.$month.'Day: '.$day.'Year: '.$year; //output Month: 04 Day:30 Year: 1973 ?>
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.