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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
4번째 줄: 4번째 줄:
==Bash==
==Bash==
[[category: Bash]]
[[category: Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
str='hello world'
str='hello world'
echo ${str%%ll*}
echo ${str%%ll*}
12번째 줄: 12번째 줄:
echo ${str%%x*}
echo ${str%%x*}
# hello world
# hello world
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[category:PHP]]
[[category:PHP]]
<source lang='php'>
<syntaxhighlight lang='php'>
echo strstr('hello world', 'll', true);
echo strstr('hello world', 'll', true);
echo strstr('hello world', 'l', true);
echo strstr('hello world', 'l', true);
23번째 줄: 23번째 줄:
# he
# he
#  
#  
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
function substr_before($needle, $haystack) { return strstr($haystack, $needle, true); }
function substr_before($needle, $haystack) { return strstr($haystack, $needle, true); }


33번째 줄: 33번째 줄:
# he
# he
#  
#  
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:36 판

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