简体   繁体   English

在没有HTTP或www的php中进行URl模式匹配

[英]URl pattern Matching in php without http or www

I have a html file that has some link like 我有一个HTML文件,其中包含一些链接,例如

<a href="clash/football/a-vs-b">

<a href="clash/football/dsfdsfds-vs-erer">

I use this $regex_pattern = "/^[^.]+((\\.[^.\\/]{1,3}\\b){1,2}).*$/"; 我用这个$regex_pattern = "/^[^.]+((\\.[^.\\/]{1,3}\\b){1,2}).*$/";

pattern to find this type of URL. 模式来查找这种类型的URL。 But can not get this. 但是无法得到这个。 Please somebody help me. 请有人帮我。 I need to match total tag like "<a href="clash/football/a-vs-b">" 我需要匹配"<a href="clash/football/a-vs-b">"类的总标签

Regular expressions describe operations on regular languages and html is not a regular language! 正则表达式描述了对常规语言的操作,而html不是常规语言! You'll be better of by using DomDocument . 使用DomDocument会更好。

You could then take a look at getElementsByTagName to get all the <a href> tags. 然后,您可以查看getElementsByTagName以获取所有<a href>标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM