Home > Article > Backend Development > 这种地址有什么名称吗
$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://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";$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";$c1 = parse_url($u1, PHP_URL_QUERY);parse_str($c1, $params);echo $params['u'];
何必呢,2# 的方法其实很好,很高效。
$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 "
";echo urldecode($m2[1]);
$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, $r);echo urldecode($r[1]);preg_match('/u=([^&]+)/', $u2, $r);echo urldecode($r[1]);http://www.cnbeta.com/articles/244192.htm
$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, $r);echo urldecode($r[1]);preg_match('/u=([^&]+)/', $u2, $r);echo urldecode($r[1]);http://www.cnbeta.com/articles/244192.htm
何必呢,2# 的方法其实很好,很高效。
$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 "
";echo urldecode($m2[1]);
<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" alt="这种地址有什么名称吗" ></img>新浪乐居讯(记者 李晓娜) 金九月,烟台楼市供需两旺,完美收官。现销售排行榜已出炉,克而瑞数据显示,九月烟台六区商品房成交总金额25.88亿元,环比上涨14.5%。六区项目成交套数排行榜中,开发区华明星海湾 (论坛相册户型样板间点评地图搜索)成交320套,列位第一。万达以2.63亿的成交金额一举拿下</body></html>
那你把 u 去掉不就行了?
那你把 u 去掉不就行了?
谢谢你的回复。
那你把 u 去掉不就行了?
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=[\'"]([^\'"]+)[\'"].* alt="这种地址有什么名称吗" >/siU', $desc, $match); return (!empty($match[1]))?str_replace($match[1][0], haloURI::getRealUrl($match[1][0]), $desc):$desc; }