简体   繁体   English

为什么 get_meta_tags() 不能正常工作

[英]Why get_meta_tags() not working properly

I have used get_meta_tags("squidoo.com") to get keywords and description.我使用 get_meta_tags("squidoo.com") 来获取关键字和描述。 When I run in my PC with WAMP Server 2.1 (PHP 5.3) it working perfectly but when i upload to linux server PHP 5.2 It is not work for squidoo.com.当我使用 WAMP Server 2.1 (PHP 5.3) 在我的 PC 中运行时,它运行良好,但是当我上传到 linux 服务器 PHP 5.2 时,它不适用于 squidoo.Z4D236D9A2D102C50ZFE6AD1

I test with我用

$datas = get_meta_tags("http://squidoo.com")  

$keywrds = $datas['keywords'];
$desc = $datas['description'];

When I run in my PC it work perfectly but there is blank data in $keywrds and $desc when i upload to server.当我在我的电脑上运行时,它运行良好,但是当我上传到服务器时,$keywrds 和 $desc 中有空白数据。

Above code work with almost sites, I got error with www.squidoo.com and some others only上面的代码几乎适用于网站,我在 www.squidoo.com 和其他一些网站上遇到了错误

you haven't given us much info on the errors you're getting, but the most likely reason for this to fail is that your local server is configured to allow commands which open a file to use a URL, whereas your Linux server isn't.您没有向我们提供有关您遇到的错误的太多信息,但失败的最可能原因是您的本地服务器配置为允许打开文件的命令使用 URL,而您的 Linux 服务器不是吨。

This is a PHP.ini configuration setting, which specifies whether you can use URLs as file names.这是一个 PHP.ini 配置设置,它指定是否可以使用 URL 作为文件名。 If it is switched off then PHP won't allow you to open files from a remote site and will only allow it from files on its local server.如果它被关闭,那么 PHP 将不允许您从远程站点打开文件,并且只允许从其本地服务器上的文件打开文件。

Switching it off is considered good security practice, so most PHP hosting providers will turn it off by default.将其关闭被认为是良好的安全实践,因此大多数 PHP 托管服务提供商将默认将其关闭。 You may be able to turn it on youself, depending on your provider, or you may just have to work around it by downloading the URL using CURL and then examining the downloaded file.您可以自己打开它,具体取决于您的提供商,或者您可能只需要通过使用 CURL 下载 URL 然后检查下载的文件来解决它。

See the PHP manual entry for this config setting here: http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen在此处查看此配置设置的 PHP 手册条目: http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

That might be because you have local file called squidoo.com on your WAMP setup.这可能是因为您的 WAMP 设置中有名为squidoo.com的本地文件。 If you want it to work on the actual website, then you have to provide an URL:如果您希望它在实际网站上运行,则必须提供 URL:

print_r(
   get_meta_tags("http://squidoo.com") 
);

Notice the http:// which differentiates web addresses from files.请注意http:// ,它将 web 地址与文件区分开来。

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

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