PHP中字符串截取多个子字符串

2024-11-02 16:25:59
推荐回答(3个)
回答1:

可以使用正则表达式获取,例子代码:

  $str=<<
            
             
            
             
            
             
            
END;
  if (preg_match_all("|'(http:[^?]+)|",$str,$reg)) print_r($reg[1]);
?>

运行结果:

Array
(
    [0] => http://localhost/shopnc/data/upload/shop/editor/web-101-101-1.jpg
    [1] => http://localhost/shopnc/data/upload/shop/editor/web-101-101-2.jpg
    [2] => http://localhost/shopnc/data/upload/shop/editor/web-101-101-3.jpg
    [3] => http://localhost/shopnc/data/upload/shop/editor/web-101-101-4.jpg
)

满足你的要求了吧?

回答2:

用Javascript吧 php不太适合做这样的事情

回答3:

function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u"){
$ar[$k] = mb_convert_encoding(pack("H4",substr($v,-4)),"gb2312","UCS-2");
}elseif(substr($v,0,3) == "&#x"){
$ar[$k] = mb_convert_encoding(pack("H4",substr($v,3,-1)),"gb2312","UCS-2");
}elseif(substr($v,0,2) == "&#") {
$ar[$k] = mb_convert_encoding(pack("H4",substr($v,2,-1)),"gb2312","UCS-2");
}
}
return join("",$ar);
}

$str = '/?y=%u597D&m=%u554A&h=%20';
$query = parse_url($str,PHP_URL_QUERY);
parse_str($query);
echo unescape($y);
?>
求采纳为满意回答。