Home > Backend Development > PHP Tutorial > 紧急求救,关于正则表达式的问题

紧急求救,关于正则表达式的问题

WBOY
Release: 2016-06-23 14:04:06
Original
912 people have browsed it

  


                            全部中山珠海潮州东莞佛山茂名揭阳清远梅州河源广州江门惠州云浮阳江肇庆湛江汕尾汕头深圳韶关
                        


上面那段代码,我想提取城市名称和链接,应该如果操作,请好心人帮忙,非常感谢,我对正则表达式不是很了解


回复讨论(解决方案)

preg_match_all('/]+href="?([^>"]+)"?\s*[^>]*>(.+?)/i',$data,$arr); 

把所有的span内容定义成一个字符串,然后写一个正则表达式匹配,返回一个数组,打印数组,看到结构,根据需要取值:
$str="全部中山珠海潮州东莞佛山茂名揭阳清远梅州河源广州江门惠州云浮阳江肇庆湛江汕尾汕头深圳韶关";
$reg="/\(.*?)\/mi";
preg_match_all($reg,$str,$arr);
echo "

";
?>

preg_match_all('/<a[^>]+href=["\']?([^>"\']+)["\']?\s*[^>]*>(.+?)<\/a>/i', $str, $arr, PREG_SET_ORDER);
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template