2009-08-18 2 views

답변

9
preg_replace('/\?/', 'replacement', $original, 1) 
2

, 당신은 preg_ 솔루션을 필요로하지 않을 수는 "간단한"않는 str_replace뿐만 아니라 트릭을 할 수 있습니다

www.php.net/str_replace

0

당신이 원하는 경우 문자열 testing ??에서 하나의 물음표를 대체하지 않도록하십시오 당신은 할 수 :

// using negative lookbehind/ahead to ensure that the question mark 
// doesn't have a "friend" 
$new = preg_replace('/(?<!\?)\?(?!\?)/', 'replacement', $original); 

당신 만의에서 첫 번째 물음표를 교체하고자하는 경우 tring-chaos의 대답은 당신이 원하는 것입니다