Posttwo
Posttwo

Reputation: 1274

How can I find a word and a title on a list of pages

Im trying to find if a word exists on the page and the pages title in multiple pages My code is

<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]";
}
?>

It works if I put in a single link in to the textarea. But I want it to work if I put in more then one link.

Upvotes: 1

Views: 133

Answers (1)

mgraph
mgraph

Reputation: 15338

put this in your textarea http://www.test.com,http://www.test2.com

then:

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";
    }

Upvotes: 1

Related Questions