Autor Zpráva
Pavel Kr.
Profil *
Ahoj,

neznáte někdo nějaký tool nebo jednoduché řešení, které projde HTML soubor a smaže neplatné odkazy na soubory ve stejném adresáři?

Díky.
xxxadam577
Profil
us v php načíst stránku a když to nepůjde... tak neexistuje :D
tpmar
Profil
Pavel Kr.:
V mém případě bych si sepsal PHP skript pomocí SimpleHTMLDom.

Vypadal by cca následovně.

<?php
include "simple_html_dom.php";

function get_http_response_code($theURL) {
    $headers = get_headers($theURL);
    return substr($headers[0], 9, 3);
}

// $page - stranka pro kontrolu (index.html,..)
// $url_address - Adresa, kde se soubor nachazi (http://example.com/some_folder, http://localhost/some_project,..)
function removeAnchors($page, $url_address)
{
    // Nacteni stranky
    $html = file_get_html($page);

    // Nacteni vsech odkazu
    foreach($html->find('a') as $element) {

        // Zjisteni dle HTTP hlavicky, jestli je smazany
        if (get_http_response_code($url_address."/".$element->href) == "404") {

            // Smazani odkazu
            echo $element->parent()->outertext = ''; 
        }
    }

    $html->save($page);

}

removeAnchors("index.html", "http://muj-projekt.cz");

?>

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0