目前我是通过从网上抄来的正则实现的,可是并不能达到我想要效果。
目前我的方案是:
$text=file_get_contents('404.html');
preg_match('/<time[^>]*itemprop=\"datePublished\".*?>.*?<\/time>/ism',$text,$match);
print($match[0]);
可是最终输出的内容是
<time datetime="2017-02-20T18:41:00+08:00" itemprop="datePublished">2017年2月20日</time>
我想要的是输出2017年2月20日,也就是原因里面的内容,可是对正则不了解,看了百科完全一脸懵逼。请问该如何实现?或是正则该怎么写才能输出里面的内容
This time is similar to html tags. You can use PHP's html tag removal function to remove the nested tags and it will be fine. Take a look at the code below and try using the tag removal function strip_tags(). For more specific usage, you can check the manual.
1. https://github.com/bupt1987/h...
2. https://github.com/paquettg/p...
We directly recommend two php to parse html, similar to jQuery. Users can read html elements
strip_tags is a function of php, used to remove html tags from strings, so you can use strip_tags here. Since you use regular expressions, you can also use regular expressions directly to optimize the program. Please see the rules below