"함수 substr until()"의 두 판 사이의 차이

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


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
<syntaxhighlight lang='PHP'>
function substr_until($needle, $haystack) { return ($pos=strpos($haystack,$needle))? substr($haystack,0,$pos).$needle : false; }
function substr_until($needle, $haystack) { return ($pos=strpos($haystack,$needle))? substr($haystack,0,$pos).$needle : false; }


28번째 줄: 28번째 줄:
# hel
# hel
#
#
</source>
</syntaxhighlight>


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

2020년 11월 2일 (월) 02:36 기준 최신판

substr_until

1 Bash[ | ]

haystack='hello world'
needle='ll'
echo ${haystack%%$needle*}$needle
# hell
needle='l'
echo ${haystack%%$needle*}$needle
# hel
needle='x'
echo ${haystack%%$needle*}$needle
# hello worldx

2 PHP[ | ]

function substr_until($needle, $haystack) { return ($pos=strpos($haystack,$needle))? substr($haystack,0,$pos).$needle : false; }

echo substr_until('ll', 'hello world');
echo substr_until('l', 'hello world');
echo substr_until('x', 'hello world'); // bool(false)
# hell
# hel
#

3 같이 보기[ | ]

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