note 29377 added to ref.strings

From: Date: Tue, 11 Feb 2003 21:39:24 +0000
Subject: note 29377 added to ref.strings
Groups: php.notes 
Request: Send a blank email to php-notes+get-43796@lists.php.net to get a copy of this message
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!!! -- http://www.php.net/manual/en/ref.strings.php http://master.php.net/manage/user-notes.php?action=edit+29377 http://master.php.net/manage/user-notes.php?action=delete+29377 http://master.php.net/manage/user-notes.php?action=reject+29377

« previous php.notes (#43796) next »