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

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:56 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
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 }}