简体   繁体   English

检索远程页面的标题

[英]retrieving the title of a remote page

I have a little problem with the pattern for retrieving the title of the remote page while same pattern is giving the result here is the sample. 我对检索远程页面标题的模式有一点问题,而相同模式给出的结果是样本。

preg_match_all('|<title>(.*)</title>|U',$this->data,$title);

is for other url and giving the result . 用于其他网址并给出结果。 While following return the empty array 同时返回空数组

preg_match_all('|<title>(.*)</title>|U', $valD, $title);

can any on tell me the is any problem with these lines. 可以告诉我这些线路有什么问题。

Where $this->data and $valD holds the content of two different urls for different servers. 其中$ this-> data和$ valD保存不同服务器的两个不同URL的内容。

Please help me. 请帮我。 I tried it to solve it but I failed to solve it. 我试过它来解决它,但我没能解决它。 So I requesting the you all to tell me my faults in this. 所以我请求大家告诉我我的错误。

Thank you. 谢谢。

If you are matching HTML, then you should also expect uppercase tags. 如果您匹配HTML,那么您还应该期望大写标记。 Add the |i flag therefore. 因此添加|i标志。

The title tag might also contain newlines, which is why the |s flag should also be present. title标签也可能包含换行符,这也是|s标志也应该出现的原因。

 preg_match_all('|<title>(.*)</title>|Uis', ...

Maybe there is a line break in the title tag such like this: 也许标题标签中有换行符,如下所示:

<title>
The page title
</title>

Try 尝试

preg_match_all('|<title>[:space:]*(.*)[:space:]*</title>|U', $valD, $title);

instead. 代替。

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

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