Find a string between 2 points with PHp
Free Scripts :: PHP :: String :: Find a string between 2 points with PHp
Author: Salman Javaid
Website: http://www.salman.be
Website: http://www.salman.be
- How to find string between 2 strings with PHP.
- Find a string between two tags with PHP.
- Search a text between 2 points.
This function accepts 3 parameters and returns the string between 2 points.
Function
function findString($startPoint, $endPoint, $source) {
$m=array();
preg_match_all('/' . preg_quote($startPoint, '/') . '([^)]+)'. preg_quote($endPoint, '/').'/i', $source, $m);
return $m[1][0];
}
Calling The Function
$source='<title>welcome to my website</title>';
$startPoint='<title>';
$endPoint='</title>';
echo findString($startPoint, $endPoint, $source);
Output
welcome to my website





