Regex 获取网页标题正则表达式
我不擅长正则表达式 我正在尝试阅读网页标题。我遇到过一些具有类似Regex 获取网页标题正则表达式,regex,preg-match,Regex,Preg Match,我不擅长正则表达式 我正在尝试阅读网页标题。我遇到过一些具有类似test-Google+或Safaricom-Google+ 当我尝试用下面的代码阅读它们时,我没有标题,我怎样才能解决这个问题 $header_data = Array(); if (preg_match("@<title *>(.*?)<\/title*>@si", $file, $header_data)) { $title = trim($header_data[1]); } $h
test-Google+
或Safaricom-Google+
当我尝试用下面的代码阅读它们时,我没有标题,我怎样才能解决这个问题
$header_data = Array();
if (preg_match("@<title *>(.*?)<\/title*>@si", $file, $header_data)) {
$title = trim($header_data[1]);
}
$header_data=Array();
if(preg_match(“@(.*?@si)”,$file,$header_data)){
$title=trim($header_data[1]);
}
这里的问题是使用*
- 指示前面的正则表达式/字符可以出现0次或多次
(*)
谢谢……我已经测试过了,但仍然没有working@Andreas很抱歉,我使用了这个preg_匹配(@(.*)@si,$file,$header_数据),而不是preg_匹配(“/(.*)/”,$file,$header_数据);
<title.*>(.*?)<\/title>