note 29377 deleted from ref.strings by didou
| From: | didou@php.net | Date: | Sun, 18 May 2003 00:52:33 +0000 |
| Subject: | note 29377 deleted from ref.strings by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48300@lists.php.net to get a copy of this message | ||
Note Submitter: tcn@pandora.be
----
Hi,
I was searching for an option to extract the contents of a string between for example [a] and [b].
I was unable to find it, so I created something myself:
function str_extract ($String,$CharBegin,$CharEnd)
{
$StringLength=strlen($String);
$Begin=strpos($String,$CharBegin);
$End=strpos($String,$CharEnd)-$Begin+strlen($CharEnd);
return substr ($String, $Begin, $End);
}
It works like this: str_extract (string haystack, string begin, string end);
For example: echo str_extract ("Bla bla [a]foo[b] bla bla",
"[a]","[b]");
Would produce: [a]foo[b]
Hopes this helpes someone!!!