note 74546 deleted from function.strpos by bjori
| From: | bjori@php.net | Date: | Tue, 17 Apr 2007 09:32:35 +0000 |
| Subject: | note 74546 deleted from function.strpos by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125505@lists.php.net to get a copy of this message | ||
Note Submitter: php at mattch dot net
Reason: useless
----
Get text between two strings, nonencasing. Results are returned by array.
The following is a modification of the code provided by mvp at mvpprograms dot com. Instead of
substr'ing, it uses an offset. When using extremely large strings I found it's more
reliable than some others on this page, and has been performing 400x faster than his original. Hope
it helps.
<?php
function TextBetweenArray($s1,$s2,$s,$offset=0){
$myarray=array();
$s1=strtolower($s1);
$s2=strtolower($s2);
$L1=strlen($s1);
$scheck=strtolower($s);
do {
$pos1 = strpos($scheck,$s1,$offset);
if($pos1 !== false) {
$pos2 = strpos($scheck,$s2,$pos1+$L1);
if($pos2 !== false) {
$myarray[]=substr($s,$pos1+$L1,$pos2-$pos1-1);
$offset=$pos2;
}
}
} while (($pos1!==false) && ($pos2!==false));
return $myarray;
}
?>