함수 substrBefore()

Jmnote (토론 | 기여)님의 2022년 5월 19일 (목) 11:06 판 (Jmnote님이 함수 substr before() 문서를 함수 string before() 문서로 이동했습니다)
substr_before

1 Bash

str='hello world'
echo ${str%%ll*}
# he
echo ${str%%l*}
# he
echo ${str%%x*}
# hello world

2 PHP

echo strstr('hello world', 'll', true);
echo strstr('hello world', 'l', true);
echo strstr('hello world', 'x', true); // bool(false)
# he
# he
#
function substr_before($needle, $haystack) { return strstr($haystack, $needle, true); }

echo substr_before('ll', 'hello world');
echo substr_before('l', 'hello world');
echo substr_before('x', 'hello world'); // bool(false)
# he
# he
#

3 같이 보기

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