PHP Regular Expression with Examples

Some important PHP regular expression functions

<?php 
$str = "Regular expression is used to perform text based search operations";
$pattern = "/ion/i";
echo preg_match($pattern, $str);
?>
<?php 
$str = "Regular expression is used to perform text based search operations";
$pattern = "/ixz/i";
echo preg_match($pattern, $str);
?>
<?php 
$str = "Regular expression is used to perform text based search operations";
$pattern = "/ion/i";
echo preg_match_all($pattern, $str);
?>
<?php 
$str = "Regular expression is used to perform text based search operations";
$pattern = "/perform text based search operations/i";
echo
preg_replace($pattern, 'find sequence of characters inside a string', $str);
?>

--

--

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bipsmedium

Bipsmedium

25 Followers

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.