1

我试图查找页面上是否存在一个单词以及多个页面中的页面标题我的代码是

<form method="post">
<label for="adres">Adres</label><br /><textarea id="adres" name="adres"></textarea><br />
<input type="submit" value="Generate" />
</form>


<?php
if ($_POST){
$adres = $_POST['adres'];

function getTitle($Url){
    $str = file_get_contents($Url);
    if(strlen($str)>0){
        preg_match("/\<title\>(.*)\<\/title\>/",$str,$title);
        return $title[1];
    }
}

$name = getTitle("$adres");

function check_url($url) {
    $page = file_get_contents($url);
    $code = 'alt="mh"';
    if (strpos($page, $code) == TRUE) {
    $soft = '[img]http://www.ufs.pl/forum/images/icons/icon3.png[/img]';
    echo "$soft";
    }
}
$icon = check_url("$adres");
echo "$icon [url=$adres] $name [/url]";
}
?>

如果我将单个链接放入文本区域,它就可以工作。但是,如果我输入多个链接,我希望它能够工作。

4

1 回答 1

1

把它放在你的文本区域http://www.test.com,http://www.test2.com

然后:

if (isset($_POST['adres'])){
    $adres = explode(",", $_POST['adres']);

    foreach($adres as $link){
       $name = getTitle($link);
       echo "Title:".$name;
       $icon = check_url($link);
       echo "$icon [url=$link] $name [/url]";

    }
}

function getTitle($Url){
    $str = file_get_contents($Url);
    if(strlen($str)>0){
        preg_match("/\<title\>(.*)\<\/title\>/",$str,$title);
        return $title[1];
    }
}
function check_url($url) {
    $page = file_get_contents($url);
    $code = 'alt="mh"';
    if (strpos($page, $code) == TRUE) {
    $soft = '[img]http://www.ufs.pl/forum/images/icons/icon3.png[/img]';
    echo "$soft";
    }
于 2012-05-05T20:53:00.253 回答