varemenos
4/4/2012 - 8:13 AM

PHP - return string between start and end strings

PHP - return string between start and end strings

<?php
	function GetBetween($content,$start,$end){
		$r = explode($start, $content);
		if (isset($r[1])){
			$r = explode($end, $r[1]);
			return $r[0];
		}
		return '';
	}

/*
	source:
	http://www.jonasjohn.de/snippets/php/get-between.htm

	example:
	$x = 'qwertyuiop';
	$start = 'ert';
	$end = 'op';
	echo getBetween($x, $start, $end);
	result:
	yui
*/

?>