Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 设置页面';基于另一个';谁的URL标题?_Php_Javascript - Fatal编程技术网

Php 设置页面';基于另一个';谁的URL标题?

Php 设置页面';基于另一个';谁的URL标题?,php,javascript,Php,Javascript,如何设置标题标记内部HTML以匹配存储在变量:$URL中的URL中的标题标记 我应该以某种方式检索url$url上的标题,然后在我的标题标记中回显它 我该怎么做 这是为这个网站准备的,以防你好奇: 谢谢检索URL(使用或使用您拥有的内容),解析HTML,找到标题标记,提取其文本,并将其显示在您自己的网页中。尝试以下操作: $url = 'http://www.google.com'; $htm = file_get_contents($url); $title = ''; if(preg_ma

如何设置标题标记内部HTML以匹配存储在变量:$URL中的URL中的标题标记

我应该以某种方式检索url$url上的标题,然后在我的标题标记中回显它

我该怎么做

这是为这个网站准备的,以防你好奇:

谢谢

检索URL(使用或使用您拥有的内容),解析HTML,找到
标题
标记,提取其文本,并将其显示在您自己的网页中。

尝试以下操作:

$url = 'http://www.google.com';
$htm = file_get_contents($url);
$title = '';
if(preg_match('/\<title\>(.*?)\<\/title\>/',$htm,$match)){
    $title = $match[1];
}
echo $title;

//set the current page title to the retrieved title using js
echo '<script>document.title="' . addslashes($title) . '";</script>';
$url='1!'http://www.google.com';
$htm=文件内容($url);
$title='';
if(preg_match('/\(.*?\/'),$htm,$match)){
$title=$match[1];
}
echo$标题;
//使用js将当前页面标题设置为检索到的标题
echo'document.title=“”.addslashes($title)。“;”;

如果要通过PHP进行检索,为什么要添加[javascript]标记?=)我原以为可以用Ajax实现,但老实说,我不知道如何实现。这涉及到同样的问题。您应该使用适当的DOM解析器,而不是正则表达式。还有,你为什么不附和一个标题标签呢?这是
document.title
,顺便说一句,如果你坚持用JavaScript来做这件事。现在我错过了,谢谢,这是document.title;,是的,echo$title就足够了,至于用javascript做这个,我只是建议如何用JS做。在我看来,在只需要标题的时候使用DOM解析器太过分了。虽然我在标题标记中回显了$title,但这很好。