PHP 함수 substr after before(), substr from until()

PHP substr_from_until, substr_after_before
PHP get_between

1 substr_after_before[ | ]

function substr_after_before($after, $before, $haystack) {
	$pos1 = strpos($haystack, $after);
	if($pos1 === false) return false;
	$pos1 += strlen($after);
	$pos2 = strpos($haystack, $before, $pos1);
	if($pos2 === false) return false;
	return substr($haystack, $pos1, $pos2 - $pos1);
}

2 substr_from_until[ | ]

function substr_from_until($from, $until, $haystack) {
	$pos1 = strpos($haystack, $from);
	if($pos1 === false) return false;
	$pos2 = strpos($haystack, $until, $pos1+strlen($from));
	if($pos2 === false) return false;
	return substr($haystack, $pos1, $pos2+strlen($until)-$pos1);
}

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}