【问题标题】:Stopping PHP script putting URL's in address bar?停止将 URL 放在地址栏中的 PHP 脚本?
【发布时间】:2012-04-25 15:55:04
【问题描述】:

我有一个从 URL 列表中提取元数据的脚本,但是当我尝试提取太多时,它说 URL 太长并且无法运行。

我的问题是如何阻止这种情况发生?

<?php
ini_set( 'default_charset', 'UTF-8' );
error_reporting(E_ALL);
//ini_set( "display_errors", 0);
function parseUrl($url){
    //Trim whitespace of the url to ensure proper checking.
    $url = trim($url);
    //Check if a protocol is specified at the beginning of the url. If it's not,   prepend 'http://'.
    if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
            $url = "http://" . $url;
    }
    //Check if '/' is present at the end of the url. If not, append '/'.
    if (substr($url, -1)!=="/"){
            $url .= "/";
    }
    //Return the processed url.
    return $url;
}
//If the form was submitted
if(isset($_GET['siteurl'])){
    //Put every new line as a new entry in the array
    $urls = explode("\n",trim($_GET["siteurl"]));
    //Iterate through urls
    foreach ($urls as $url) {
            //Parse the url to add 'http://' at the beginning or '/' at the end if not   already there, to avoid errors with the get_meta_tags function
            $url = parseUrl($url);
            //Get the meta data for each url
            $tags = get_meta_tags($url);
            //Check to see if the description tag was present and adjust output   accordingly
            $tags = NULL;
$tags = get_meta_tags($url);
if($tags)
echo "<tr><td>Description($url)</td><td>" .$tags['description']. "</td></tr>";
else 
echo "<tr><td>Description($url)</td><td>No Meta Description</td></tr>";
    }
}
?>

【问题讨论】:

  • 你评论很好,但不要评论每一行! “遍历 url” 这一点从代码本身就很明显了!
  • GET 方法不适用于 LONG 数据。请改用 POST。
  • 谢谢!好吧,我会限制我的评论;)

标签: php


【解决方案1】:

然后发布网址。 GET 是limited

【讨论】:

    猜你喜欢
    • 2020-04-29
    • 2015-11-27
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多