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

31번째 줄: 31번째 줄:


==같이 보기==
==같이 보기==
*[[함수 substr_after]]
*[[함수 substr_after()]]
*[[함수 substr_before]]
*[[함수 substr_before()]]
*[[함수 substr_from]]
*[[함수 substr_from()]]
*[[함수 substr]]
*[[함수 substr()]]
*[[PHP 함수 substr after, before, from, until]]
*[[PHP 함수 substr after, before, from, until]]

2016년 8월 9일 (화) 15:02 판

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