就像我用相反SUBSTR的
substr($sometext, 4, 10)
選擇一個字符串的某一部分,我怎麼能刪除某些部分從字符串使用精確定位是什麼?如果要刪除,直到最後出現,使用strrpos可以不用strpos
$new_string = substr($sometext, 0, 4) . substr($sometext, 10);
就像我用相反SUBSTR的
substr($sometext, 4, 10)
選擇一個字符串的某一部分,我怎麼能刪除某些部分從字符串使用精確定位是什麼?如果要刪除,直到最後出現,使用strrpos可以不用strpos
$new_string = substr($sometext, 0, 4) . substr($sometext, 10);
您就可以使用兩個子。
$new_text = substr($sometext,0,4) . substr($sometext, 10, strlen($sometext));
$string = "Hello World";
$output = substr($string, strpos($string, "W"));
:
你可以得到的Jiggy與它使用array_splice:
$sometext = 'Hello, worlds! How are ya?';
echo str_splice($sometext, 4, 10); // o, worlds!
function str_splice($input, $offset, $length = 0) {
$chars = str_split($input);
return implode(array_splice($chars, $offset, $length));
}
一個更簡單的解決辦法是使用substr_replace一個空字符串替換:
$new_string = substr_replace($sometext, '', 4, 10);
這不是如何使用strpos,除非你正在將4轉換爲一個字符的序數值。你的意思是substr? – 2012-03-16 16:29:00
是的,這就是我的意思,對不起@christopher_b – Shpat 2012-03-16 16:43:33