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

  • 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

Comments

No comments. Be the first one.

Leave a comment

Full Name*
Comments*
Security Code*

Our Partners

Getty Icons  Free MP3 Songs
Free High Quality Images  Learn Free Languages 
Opal Hosting  R-Tech Solutions
Virtualxone
  • Submit a Script

    Click here to submit your script.