Return to Snippet

Revision: 7355
at July 18, 2008 20:00 by jamesming


Initial Code
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;
	}
  
function TextBetween($s1,$s2,$s){
			$s1 = strtolower($s1);
			$s2 = strtolower($s2);
			$L1 = strlen($s1);
			$scheck = strtolower($s);
			if($L1>0){$pos1 = strpos($scheck,$s1);} else {$pos1=0;}
			if($pos1 !== false){
				if($s2 == '') return substr($s,$pos1+$L1);
				$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
				if($pos2!==false) return substr($s,$pos1+$L1,$pos2);
			}
			return '';
	}

Initial URL


Initial Description
Two functions.  1) Find the string between characters.  2) Create array of strings found between two characters.

Initial Title
extract string between

Initial Tags
text

Initial Language
PHP