"함수 substrBefore()"의 두 판 사이의 차이

(새 문서: ;rm_from category:String ==PHP== category:PHP <source lang='php'> function rm_from($needle, $haystack, $preservation = true) { $pos = strpos($haystack, $needle); if($pos !=...)
 
잔글 (Jmnote 사용자가 Rm from 문서를 함수 substr before 문서로 옮겼습니다)
(차이 없음)

2015년 2월 20일 (금) 17:14 판

rm_from

1 PHP

function rm_from($needle, $haystack, $preservation = true) {
	$pos = strpos($haystack, $needle);
	if($pos !== false) return substr($haystack, 0, $pos);
	if($preservation) return $haystack;
	return false;
}
$result1 = rm_from('ll', 'hello');
$result2 = rm_from('al', 'hello');
$result3 = rm_from('al', 'hello', false);
echo "[$result1]"; // [he]
echo "[$result2]"; // [hello]
echo "[$result3]"; // []
function rm_from($needle, $haystack, $preservation = true) {
	$arr = explode($needle, $haystack, 2);
	if( count($arr)<2 && !$preservation ) return false;
	return $arr[0];
}

2 같이 보기

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