当前位置: 代码迷 >> PHP >> 匹配字符串解决办法
  详细解决方案

匹配字符串解决办法

热度:97   发布时间:2012-04-05 12:42:40.0
匹配字符串
如何返回url呢???

传入字符串:
HTML code
<a href="http://www.macaucentral.com/dev/index.php/beauty-content/6579-celina-beauty-centre">莎莉娜美容中心 Celina ...</a>


返回字符串
HTML code
http://www.macaucentral.com/dev/index.php/beauty-content/6579-celina-beauty-centre


------解决方案--------------------
PHP code
<?php
$str='<a href="http://www.macaucentral.com/dev/index.php/beauty-content/6579-celina-beauty-centre">莎莉娜美容中心 Celina ...</a>';
$pattern='/<a[^>]*href="([^"\']*)"/';
preg_match($pattern,$str,$matchs);
print_r($matchs);

------解决方案--------------------
preg_match('/href="([^"]*)"/',$str,$arr);
echo $arr[1];
  相关解决方案