- 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
$startPoint='< title>'; $endPoint='< /title>'; $source='< title>welcome to my website< /title>' echo findString($startPoint, $endPoint, $source);
Output
welcome to my website
Herman Strauss – May 05, 2013
Thanks a lot!!
Sazi – February 02, 2013
So much thanks , i was looking for this pattern
Ezequiel Mendez – September 09, 2011
Awesome thanks a lot!