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

잔글 (Jmnote 사용자가 함수 substr before 문서를 함수 substr before() 문서로 옮겼습니다)
1번째 줄: 1번째 줄:
[[category:String]]
[[category:String]]
;substr_before
;substr_before
==Bash==
[[category: Bash]]
<source lang='bash'>
str='hello world'
echo ${str%%ll*}
# he
echo ${str%%l*}
# he
echo ${str%%x*}
# hello world
</source>


==PHP==
==PHP==

2016년 8월 9일 (화) 14:55 판

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 }}