- substr_until
1 Bash[ | ]
Bash
Copy
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[ | ]
PHP
Copy
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 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.