PHP forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.
April 2024
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
282930    

Calendar Calendar

Latest topics
» Kabaddi, Kabaddi, Kabaddi, Kabaddi......PHP?
finding links in a page EmptyFri Jul 22, 2011 1:37 pm by shyamsunder

» Thousands of Free PHP Scripts Recommended
finding links in a page EmptyWed May 18, 2011 10:33 am by bizboy12

» PHP form validation problem?
finding links in a page EmptyWed Jan 12, 2011 1:25 pm by simy202

» string wrap
finding links in a page EmptySat Aug 02, 2008 2:06 pm by scvinodkumar

» retrieving current date rows
finding links in a page EmptyTue Jul 15, 2008 3:25 am by scvinodkumar

» number in words
finding links in a page EmptyTue Apr 29, 2008 3:10 pm by scvinodkumar

» Simple PHP Form Field Generator
finding links in a page EmptyFri Apr 25, 2008 12:28 pm by scvinodkumar

» PHP password generator
finding links in a page EmptyFri Apr 18, 2008 7:24 pm by scvinodkumar

» PHP Script to Extract Email Address from any text
finding links in a page EmptyFri Apr 18, 2008 7:18 pm by scvinodkumar

Search
 
 

Display results as :
 


Rechercher Advanced Search

Affiliates
free forum
 


Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

finding links in a page

Go down

finding links in a page Empty finding links in a page

Post  scvinodkumar Sat Mar 29, 2008 10:09 pm

<?php
// findlinks.php
// php code example: find links in an html page
// mallsop.com 2006 gpl
echo "<HTML><HEAD><TITLE>findlinks.php</TITLE></HEAD> \n";
echo "<BODY bgcolor=\"#336699\" text=\"000000\" link=\"#416D96\" vlink=\"#414141\" alink=\"#DDCEA2\"> \n";
echo "<form method=post action=\"$PHP_SELF\"> \n";
echo "<p><table align=\"absmiddle\" width=\"100%\" bgcolor=\"#ededed\" name=\"tablesiteopen\" border=\"0\">\n";
echo "<tr><td align=left>";
if ($_POST["FindLinks"]) {
$urlname = trim($_POST["urlname"]);
if ($urlname == "") {
echo "Please enter a urlname. <br>\n";
}
else { // open the html page and parse it

$page_title = "n/a";
$links[0] = "n/a";
//$meta_descr = "n/a";
//$meta_keywd = "n/a";

if ($handle = @fopen($urlname, "r")) { // must be able to read it
$content = "";
while (!feof($handle)) {
$part = fread($handle, 1024);
$content .= $part;
// if (eregi("</head>", $part)) break;
}
fclose($handle);
$lines = preg_split("/\r?\n|\r/", $content); // turn the content into rows

// boolean
$is_title = false;
//$is_descr = false;
//$is_keywd = false;
$is_href = false;
$index = 0;

//$close_tag = ($xhtml) ? " />" : ">"; // new in ver. 1.01
foreach ($lines as $val) {
if (eregi("<title>(.*)</title>", $val, $title)) {
$page_title = $title[1];
$is_title = true;
}
if (eregi("<a href=(.*)</a>", $val, $alink)) {

$newurl = $alink[1];
$newurl = eregi_replace(' target="_blank"', "", $newurl);
$newurl = trim($newurl);
$pos1 = strpos($newurl, "/>");
if ($pos1 !== false) {
$newurl = substr($newurl, 1, $pos1);
}
$pos2 = strpos($newurl, ">");
if ($pos2 !== false) {
$newurl = substr($newurl, 1, $pos2);
}
$newurl = eregi_replace("\"", "", $newurl);
$newurl = eregi_replace(">", "", $newurl);

//if (!eregi("http", $newurl)) { // local
// $newurl = "http://".$_SERVER["HTTP_HOST"]."/".$newurl;
// }
if (!eregi("http", $newurl)) { // local
$pos1 = strpos($newurl, "/");
if ($pos1 == 0) {
$newurl = substr($newurl, 1);
}
$newurl = $urlname.$newurl;
}

// put in array of found links
$links[$index] = $newurl;
$index++;
$is_href = true;

}

} // foreach lines done

echo "<p><b>Page Summary</b><br>\n";
echo "<b>Url:</b> ".$urlname."<br>\n";
if ($is_title) {
echo "<b>Title:</b> ".$page_title."<br>\n";
}
else {
echo "No title found<br>\n";
}
echo "<b>Links:</b><br>\n";
if ($is_href) {
foreach ($links as $myval) {
echo "Link: ".$myval."<br>\n";
}
}
else {
echo "No links found<br>\n";
}
echo "End</p>\n";
} // fopen handle ok
else {
echo "<br>The url $urlname does not exist or there was an fopen error.<br>";
}
echo "Press the back button to try again.<br>";
} // end else urlname given
} // else find links now submit
else {
$urlname = "http://www.google.com/intl/en/about.html"; // or whatever page you like
echo "<p><b>findlinks.php example</b><br>\n";
echo "File or URL: <input type=\"TEXT\" name=\"urlname\" value=\"$urlname\" maxlength=\"255\" size=\"80\"><br>\n";
echo "<input type=\"SUBMIT\" name=\"FindLinks\" value=\"Find\"></font><br></p> \n";
}
echo "</td></tr>";
echo "</table></p>";
echo "</form></BODY></HTML>\n";

?>

scvinodkumar
Admin

Posts : 40
Join date : 2008-01-30

https://solutions.aforumfree.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum