$u1="http://share.feedsportal.com/share/gplus/?u=http%3A%2F%2Fwww.cnbeta.com%2Farticles%2F244192.htm&t=%5B%E5%9B%BE%5D1366+x+768%E5%88%86%E8%BE%A8%E7%8E%87%2B%E8%A7%A6%E6%8E%A7+%E8%81%94%E6%83%B3ThinkPad+X240s%E8%B6%85%E6%9E%81%E6%9C%AC%E6%9B%9D%E5%85%89";
$u2="http://t1.baidu.com/it/u=http%3A%2F%2Fauto.shm.com.cn%2Fattachement%2Fjpg%2Fsite1%2F20131008%2F001e90ad746b13bdae620a.jpg&fm=30
如何用正则提出真正的地址
$u1=http://www.cnbeta.com/articles/244192.htm
$u2=http://auto.shm.com.cn/attachement/jpg/site1/20131008/001e90ad746b13bdae620a.jpg
$c1 = parse_url($u1, PHP_URL_QUERY);
parse_str($c1, $params);
echo $params['u'];
$u1="http://share.feedsportal.com/share/gplus/?u=http%3A%2F%2Fwww.cnbeta.com%2Farticles%2F244192.htm&t=%5B%E5%9B%BE%5D1366+x+768%E5%88%86%E8%BE%A8%E7%8E%87%2B%E8%A7%A6%E6%8E%A7+%E8%81%94%E6%83%B3ThinkPad+X240s%E8%B6%85%E6%9E%81%E6%9C%AC%E6%9B%9D%E5%85%89";
$u2="http://t1.baidu.com/it/u=http%3A%2F%2Fauto.shm.com.cn%2Fattachement%2Fjpg%2Fsite1%2F20131008%2F001e90ad746b13bdae620a.jpg&fm=30";
preg_match('/u=([^&]+)&/',$u1,$m1);
preg_match('/u=([^&]+)&/',$u2,$m2);
echo urldecode($m1[1]);
echo "<br>";
echo urldecode($m2[1]);
$u2 = "http://t1.baidu.com/it/u=http%3A%2F%2Fauto.shm.com.cn%2Fattachement%2Fjpg%2Fsite1%2F20131008%2F001e90ad746b13bdae620a.jpg&fm=30";preg_match('/u=([^&]+)/', $u1, $r);
echo urldecode($r[1]);preg_match('/u=([^&]+)/', $u2, $r);
echo urldecode($r[1]);http://www.cnbeta.com/articles/244192.htm
http://auto.shm.com.cn/attachement/jpg/site1/20131008/001e90ad746b13bdae620a.jpg
例如:<html><body><img src="http://t1.baidu.com/it/u=http%3A%2F%2Fsrc.house.sina.com.cn%2Fimp%2Fimp%2Fdeal%2Fb7%2F0e%2Fa%2F74e1fd81449bb857c66dc6c2812_p1_mk1_wm35.jpg&fm=30"></img>新浪乐居讯(记者 李晓娜) 金九月,烟台楼市供需两旺,完美收官。现销售排行榜已出炉,克而瑞数据显示,九月烟台六区商品房成交总金额25.88亿元,环比上涨14.5%。六区项目成交套数排行榜中,开发区华明星海湾 (论坛相册户型样板间点评地图搜索)成交320套,列位第一。万达以2.63亿的成交金额一举拿下</body></html>
public static function getRealUrl($url){
$uri=$url;
preg_match_all("/=([^&]+)&/", $url, $match);
if(is_array($match[1]) && sizeof($match[1])>=1){
$uri=$match[1][0];
}
return urldecode($uri);
}
上面的方法在别的地方也有调用,下面的是输出描述 public function coverDescriptionOut(){
//2013070302
global $str;
$desc=$str->apoDecodeCharacter($this->getDescription());
//2013100802
//处理描述的图片地址
preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/siU', $desc, $match);
return (!empty($match[1]))?str_replace($match[1][0], haloURI::getRealUrl($match[1][0]), $desc):$desc;
}
想问一下:上面的coverDescriptionOut方法怎么用preg_replace_callback方法重写一下