我在這裏有三個變量。如何將「從此變量只選擇此變量」轉換爲代碼?
$first= 'Start';
$second = 'End';
$testVar = 'Start here and here until the End more more more strings here';
如何搜索$的testvar如果它包含開始和結束串,我想啓動後最多隻能結束的字符串。
我在這裏有三個變量。如何將「從此變量只選擇此變量」轉換爲代碼?
$first= 'Start';
$second = 'End';
$testVar = 'Start here and here until the End more more more strings here';
如何搜索$的testvar如果它包含開始和結束串,我想啓動後最多隻能結束的字符串。
另一種方法是使用SUBSTR()和吊索()
:list(,$result) = explode($first,$testVar);
list($result) = explode($second,$result);
您也可以直接使用正則表達式
substr($testVar,strpos($testVar,$first),strpos($testvar,$second)+3)
看着你以前的帖子我假設這是一個PHP問題。如果是這樣你可以使用:
$first = preg_quote($first);
$second = preg_quote($second);
if(preg_match("!$first(.*?)$second!",$testVar,$m)) {
echo $m[1];
}
我也寧願用strpos,strlen的和SUBSTR:
$end_pos = strpos($testVar,$end)+strlen($end);
$result = substr($testVar, strpos($testVar,$start), $end_pos);
谷歌「正則表達式」 – fancyPants 2010-11-16 08:46:55