该字符串如下:
www.testweb.com/abc13.class.jpg" target="_blank">http://www.testweb.com/abc13.class.jpg
第1个回答 推荐于2017-09-05
<?php
function getJpgName($str) {
$reg = "([^\\/]+\\.jpg)";
preg_match($reg, $str, $result);
if (isset($result[0])) {
return $result[0];
} else {
return "";
}
}
echo getJpgName("tweb.com/abc13.class.jpg\" target=\"_blank\">
);
?>
function getJpgName($str) {
$reg = "([^\\/]+\\.jpg)";
preg_match($reg, $str, $result);
if (isset($result[0])) {
return $result[0];
} else {
return "";
}
}
echo getJpgName("tweb.com/abc13.class.jpg\" target=\"_blank\">
);
?>
没考虑高效的事,直接用正则了。。
第2个回答 2017-09-05
$text = '
<a href="www.testweb.com/abc13.class.jpg" target="_blank">
<a href="www.testweb.com/abc13.class.jpg" target="_blank">
';
$pattern = '/href\s?=\s?[\'|"]([^\'|"]*)[\'|"]/i';
var_dump(preg_get($pattern , $text));
function preg_get($pattern , $text)
{
$out = array();
preg_match_all( $pattern , $text, $out );
return $out[1];
}