Skip to content

Instantly share code, notes, and snippets.

@microweber
Created September 9, 2012 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save microweber/3683058 to your computer and use it in GitHub Desktop.
Save microweber/3683058 to your computer and use it in GitHub Desktop.
Gets a string between two key words and/or phrases.
<?php
function textbetweenarray($s1,$s2,$s){
$myarray=array();
$s1=strtolower($s1);
$s2=strtolower($s2);
$L1=strlen($s1);
$L2=strlen($s2);
$scheck=strtolower($s);
do {
$pos1 = strpos($scheck,$s1);
if($pos1!==false){
$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
if($pos2!==false){
$myarray[]=substr($s,$pos1+$L1,$pos2);
$s=substr($s,$pos1+$L1+$pos2+$L2);
$scheck=strtolower($s);
}
}
} while (($pos1!==false)and($pos2!==false));
return $myarray;
}
$str = 'hello how are you doing? hello more text doing?';
print_r(textbetweenarray('hello','doing?',$str));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment