Fw: [PHP] Get the string in between two other strings
| From: | Rick Emery | Date: | Thu, 17 Oct 2002 19:15:36 +0000 |
| Subject: | Fw: [PHP] Get the string in between two other strings | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-120384@lists.php.net to get a copy of this message | ||
the function assumes:
1) needle1 precedes needle2
2) needle1 is definately present
3) needle2 is definately present
4) needle2 is to be the first matching string after needle1, not the last
<?php
function FindIt($haystack,$needle1,$needle2)
{
$start = strpos($haystack,$needle1) + strlen($needle1);
$end = strpos($haystack,$needle2, $start);
return substr($haystack,$start,$end-$start);
}
$hay = "abcdeherexyz12345678there987654";
print FindIt($hay,"here","there");
?>
----- Original Message -----
From: "Cameron Cooke" <cameron@toucanresolve.co.uk>
To: <php-general@lists.php.net>
Sent: Thursday, October 17, 2002 6:01 AM
Subject: [PHP] Get the string in between two other strings
Hi,
I need a function to get a string in between two other strings. So you would
give the function the string to search and then you pass the first string
and last string, and the function will return the string in between.
Does anyone have this, or know how to do it. I tried but could not get it to
work.
Thanks for your help
Cameron Cooke
Toucan Resolve Ltd.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php