Jump to content
Killersites Community

saversites

Member
  • Content Count

    58
  • Joined

  • Last visited

Community Reputation

1 Neutral

About saversites

  • Rank
    Member

Recent Profile Visitors

245 profile views
  1. saversites

    Why Query Fails To Pull Data From Data Base ?

    I have error reporting on on one of the included files. Not getting any error. <?php //ERROR REPORTING CODES. declare(strict_types=1); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); ?> Ok, I will shorten the code in this example below. The mysql queries are not working. if ($_GET["Result_SearchType"] == "Domain") { //Grabbing these: $_GET["Result_Domain"], $_GET["Result_PageType"]. $first_param = $_GET["Result_PageType"]; $second_param = $_GET["Result_Domain"]; echo "$second_param"; $query_1 = "SELECT COUNT(*) FROM submissions_index WHERE page_type = ? AND domain = ? LIMIT ?"; $stmt_1 = mysqli_prepare($conn,$query_1); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); mysqli_stmt_execute($stmt_1); $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_free_result($stmt_1); $total_pages = ceil($matching_rows_count/$Result_LinksPerPage); $query_2 = "SELECT id,date_and_time,domain,page_type,page,title,description FROM submissions_index WHERE page_type = ? AND domain = ? LIMIT ?"; $stmt_2 = mysqli_prepare($conn,$query_2); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); $result_2 = mysqli_stmt_bind_result($stmt_2,$Result_Id,$Result_LinkSubmissionDateAndTime,$Result_Domain,$Result_PageType,$Result_Page,$Result_PageTitle,$Result_PageDescription); mysqli_stmt_fetch($stmt_2); This Url should pull the data from the db tbl since there atleast one match for the query: http://localhost/test/links_stats.php?Result_SearchType=Domain&Result_PageType=Information20%PAge&Result_Domain=gmail.com&Result_LinksPerPage=25&Result_PageNumber= Look for img in previous post for what my mysql tbl lpooks like.
  2. Folks, Why are my $query_1 failing to pull data from mysql db ? I created a condition to get alert if no result is found but I do not get the alert. That means result is found. But if found, then why the following code fails to display or echo the result through html ? Trying to pull the data with these urls: http://localhost/test/links_stats.php?Result_SearchType=Domain&Result_PageType=Information20%Page&Result_Domain=gmail.com&Result_LinksPerPage=25&Result_PageNumber= http://localhost/test/links_stats.php?Result_SearchType=Page&Result_PageType=Information%20Page&Result_Page=http://go2.com/2.html&Result_LinksPerPage=25&Result_PageNumber= http://localhost/test/COMPLETE/links_stats.php?Result_SearchType=Keywords&Result_PageType=Information20%Page&Result_Keywords=go2&Result_LinksPerPage=25&Result_PageNumber= <?php //Required PHP Files. include 'config.php'; include 'header.php'; include 'account_header.php'; if (!$conn) { $error = mysqli_connect_error(); $errno = mysqli_connect_errno(); print "$errno: $error\n"; exit(); } else { ?> <body bgcolor='blue'> <?php //Get the Page Number. Default is 1 (First Page). $Result_PageNumber = $_GET["Result_PageNumber"]; if ($Result_PageNumber == "") { $Result_PageNumber = 1; } $Result_LinksPerPage = $_GET["Result_LinksPerPage"]; if ($Result_LinksPerPage == "") { $Result_LinksPerPage = 1; } $max_result = 100; //$offset = ($Result_PageNumber*$Result_LinksPerPage)-$Result_LinksPerPage; $offset = ($Result_PageNumber-1)*$Result_LinksPerPage; if ($_GET["Result_SearchType"] == "Keywords") { //Grabbing these: $_GET["Result_PageType"],$_GET["Result_Keywords"]. $first_param = $_GET["Result_PageType"]; $second_param = $_GET["Result_Keywords"]; echo "$second_param"; $query_1 = "SELECT COUNT(*) FROM submissions_index WHERE page_type = ? AND description = ? LIMIT ?"; $stmt_1 = mysqli_prepare($conn,$query_1); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); mysqli_stmt_execute($stmt_1); $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_free_result($stmt_1); $total_pages = ceil($matching_rows_count/$Result_LinksPerPage); $query_2 = "SELECT id,date_and_time,domain,page_type,page,title,description FROM submissions_index WHERE page_type = ? AND description = ? LIMIT ?"; $stmt_2 = mysqli_prepare($conn,$query_2); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); $result_2 = mysqli_stmt_bind_result($stmt_2,$Result_Id,$Result_LinkSubmissionDateAndTime,$Result_Domain,$Result_PageType,$Result_Page,$Result_PageTitle,$Result_PageDescription); mysqli_stmt_fetch($stmt_2); } elseif ($_GET["Result_SearchType"] == "Domain") { //Grabbing these: $_GET["Result_Domain"], $_GET["Result_PageType"]. $first_param = $_GET["Result_PageType"]; $second_param = $_GET["Result_Domain"]; echo "$second_param"; $query_1 = "SELECT COUNT(*) FROM submissions_index WHERE page_type = ? AND domain = ? LIMIT ?"; $stmt_1 = mysqli_prepare($conn,$query_1); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); mysqli_stmt_execute($stmt_1); $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_free_result($stmt_1); $total_pages = ceil($matching_rows_count/$Result_LinksPerPage); $query_2 = "SELECT id,date_and_time,domain,page_type,page,title,description FROM submissions_index WHERE page_type = ? AND domain = ? LIMIT ?"; $stmt_2 = mysqli_prepare($conn,$query_2); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); $result_2 = mysqli_stmt_bind_result($stmt_2,$Result_Id,$Result_LinkSubmissionDateAndTime,$Result_Domain,$Result_PageType,$Result_Page,$Result_PageTitle,$Result_PageDescription); mysqli_stmt_fetch($stmt_2); } elseif ($_GET["Result_SearchType"] == "PageTitle") { //Grabbing these: $_GET["Result_pageTitle"], $_GET["Result_PageType"]. $first_param = $_GET["Result_PageType"]; $second_param = $_GET["Result_PageTitle"]; echo "$second_param"; $query_1 = "SELECT COUNT(*) FROM submissions_index WHERE page_type = ? AND title = ? LIMIT ?"; $stmt_1 = mysqli_prepare($conn,$query_1); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); mysqli_stmt_execute($stmt_1); $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_free_result($stmt_1); $total_pages = ceil($matching_rows_count/$Result_LinksPerPage); $query_2 = "SELECT id,date_and_time,domain,page_type,page,title,description FROM submissions_index WHERE page_type = ? AND title = ? LIMIT ?"; $stmt_2 = mysqli_prepare($conn,$query_2); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); $result_2 = mysqli_stmt_bind_result($stmt_2,$Result_Id,$Result_LinkSubmissionDateAndTime,$Result_Domain,$Result_PageType,$Result_Page,$Result_PageTitle,$Result_PageDescription); mysqli_stmt_fetch($stmt_2); } elseif ($_GET["Result_SearchType"] == "Page") { //Grabbing these: $_GET["Result_Page"], $_GET["Result_PageType"]. $first_param = $_GET["Result_PageType"]; $second_param = $_GET["Result_Page"]; echo "$second_param"; $query_1 = "SELECT COUNT(*) FROM submissions_index WHERE page_type = ? AND page = ? LIMIT ?"; $stmt_1 = mysqli_prepare($conn,$query_1); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); mysqli_stmt_execute($stmt_1); $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_free_result($stmt_1); $total_pages = ceil($matching_rows_count/$Result_LinksPerPage); $query_2 = "SELECT id,date_and_time,domain,page_type,page,title,description FROM submissions_index WHERE page_type = ? AND page = ? LIMIT ?"; $stmt_2 = mysqli_prepare($conn,$query_2); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); $result_2 = mysqli_stmt_bind_result($stmt_2,$Result_Id,$Result_LinkSubmissionDateAndTime,$Result_Domain,$Result_PageType,$Result_Page,$Result_PageTitle,$Result_PageDescription); mysqli_stmt_fetch($stmt_2); } elseif ($_GET["Result_SearchType"] == "PageDescription") { //Grabbing these: $_GET["Result_PageDescription"], $_GET["Result_PageType"]. $first_param = $_GET["Result_PageType"]; $second_param = $_GET["Result_PageDescription"]; echo "$second_param"; $query_1 = "SELECT COUNT(*) FROM submissions_index WHERE page_type = ? AND description = ? LIMIT ?"; $stmt_1 = mysqli_prepare($conn,$query_1); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); mysqli_stmt_execute($stmt_1); $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_free_result($stmt_1); $total_pages = ceil($matching_rows_count/$Result_LinksPerPage); $query_2 = "SELECT id,date_and_time,domain,page_type,page,title,description FROM submissions_index WHERE page_type = ? AND description = ? LIMIT ?"; $stmt_2 = mysqli_prepare($conn,$query_2); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); $result_2 = mysqli_stmt_bind_result($stmt_2,$Result_Id,$Result_LinkSubmissionDateAndTime,$Result_Domain,$Result_PageType,$Result_Page,$Result_PageTitle,$Result_PageDescription); mysqli_stmt_fetch($stmt_2); } elseif ($_GET["Result_SearchType"] == "AnchorText") { //Grabbing these: $_GET["Result_AnchorText"], $_GET["Result_PageType"]. $first_param = $_GET["Result_PageType"]; $second_param = $_GET["Result_AnchorText"]; echo "$second_param"; $query_1 = "SELECT COUNT(*) FROM submissions_index WHERE page_type = ? AND anchor_text = ? LIMIT ?"; } $stmt_1 = mysqli_prepare($conn,$query_1); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); mysqli_stmt_execute($stmt_1); $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_free_result($stmt_1); $total_pages = ceil($matching_rows_count/$Result_LinksPerPage); $query_2 = "SELECT id,date_and_time,domain,page_type,page,title,description FROM submissions_index WHERE page_type = ? AND anchor_text = ? LIMIT ?"; $stmt_2 = mysqli_prepare($conn,$query_2); mysqli_stmt_bind_param($stmt_1,'ssi',$first_param,$second_param,$Result_LinksPerPage); $result_2 = mysqli_stmt_bind_result($stmt_2,$Result_Id,$Result_LinkSubmissionDateAndTime,$Result_Domain,$Result_PageType,$Result_Page,$Result_PageTitle,$Result_PageDescription); mysqli_stmt_fetch($stmt_2); if(!$stmt_2) { ?> <tr> <td bgcolor="#FFFFFF">No record found! Try another time.</td> </tr> <?php } else { if(($offset+1)<=$max_result) { ?> <p align="left"> <?php echo "<font color='white'><b>LINK SUBMISSION ID:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_Id</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>LINK SUBMISSION DATE & TIME:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_LinkSubmissionDateAndTime</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>DOMAIN:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_Domain</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_Page</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE TYPE:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_PageType</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE TITLE:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_PageTitle</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE DESCRIPTION:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_PageDescription</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE SEARCH STATISTICS:</b></font>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Current&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='gold'><b>Current Visitor</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Last&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='silver'><b>Last Visitor</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Latest&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='bronze'><b>Latest Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Lost&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='grey'><b>Lost Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Unhappy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='yellow'><b>Unhappy Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Happy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='green'><b>Happy Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Competing&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='red'><b>Competing Visitors</font></b></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=All&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='blue'><b>All Visitors</font></b></a>"; ?><br> <br> <br> <?php echo "<font color='white'><b>DOMAIN SEARCH STATISTICS:</b></font>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Current&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='gold'><b>Current Visitor</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Last&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='silver'><b>Last Visitor</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Latest&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='bronze'><b>Latest Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Lost&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='grey'><b>Lost Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Unhappy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='yellow'><b>Unhappy Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Happy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='green'><b>Happy Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Competing&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='red'><b>Competing Visitors</font></b></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=All&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='blue'><b>All Visitors</font></b></a>"; ?><br> <br> <br> </align> <?php //Use this technique: http://php.net/manual/en/mysqli-stmt.fetch.php while(mysqli_stmt_fetch($stmt_2)) { ?> <p align="left"> <?php echo "<font color='white'><b>LINK SUBMISSION ID:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_Id</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>LINK SUBMISSION DATE & TIME:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_LinkSubmissionDateAndTime</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>DOMAIN:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_Domain</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_Page</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE TYPE:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_PageType</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE TITLE:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_PageTitle</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE DESCRIPTION:</b></font>"; ?><br> <?php echo "<font color='white'><i>$Result_PageDescription</i></font>"; ?><br> <br> <br> <?php echo "<font color='white'><b>PAGE SEARCH STATISTICS:</b></font>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Current&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='gold'><b>Current Visitor</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Last&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='silver'><b>Last Visitor</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Latest&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='bronze'><b>Latest Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Lost&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='grey'><b>Lost Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Unhappy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='yellow'><b>Unhappy Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Happy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='green'><b>Happy Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Competing&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='red'><b>Competing Visitors</font></b></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=All&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='blue'><b>All Visitors</font></b></a>"; ?><br> <br> <br> <?php echo "<font color='white'><b>DOMAIN SEARCH STATISTICS:</b></font>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Current&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='gold'><b>Current Visitor</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Last&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='silver'><b>Last Visitor</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Latest&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='bronze'><b>Latest Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Lost&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='grey'><b>Lost Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Unhappy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='yellow'><b>Unhappy Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Happy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='green'><b>Happy Visitors</b></font></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Competing&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='red'><b>Competing Visitors</font></b></a>"; ?><br> <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=All&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='blue'><b>All Visitors</font></b></a>"; ?><br> <br> <br> </align> <tr name="pagination"> <td colspan="10" bgcolor="#FFFFFF"> Result Pages: <?php if($Result_PageNumber<$total_pages) { for($i=1;$i<=$total_pages;$i++) //Show Page Numbers in Serial Order. Eg. 1,2,3. echo "<a href=\"{$_SERVER['PHP_SELF']}?user=$user&Result_SearchType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber={$i}\">{$i}</a> "; } else { for($i=$total_pages;$i>=1;$i--) //Show Page Numbers in Reverse Order. Eg. 3,2,1. echo "<a href=\"{$_SERVER['PHP_SELF']}?user=$user&Result_SearchType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber={$i}\">{$i}</a> "; } ?> </td> </tr> <?php } } } ?> </table> <br> <br> <p align="center"><span style="font-weight:bold;"><?php echo "Search Result: <br>Searching for ...\"$second_param\" <br>Page Type: $first_param<br> Matches: $matching_rows_count <br>"; ?></span></align> <br> </div> <br> </body> </html>
  3. Php Buddies, Look at these 2 updates. They both succeed in fetching the php manual page but fail to fetch the yahoo homepage. Why is that ? The 2nd script is like the 1st one except a small change. Look at the commented-out parts in script 2 to see the difference. The added code comes after the commented-out code part. SCRIPT 1 <?php //HALF WORKING include('simple_html_dom.php'); $url = 'http://php.net/manual-lookup.php?pattern=str_get_html&scope=quickref'; // WORKS ON URL //$url = 'https://yahoo.com'; // FAILS ON URL $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); $response_string = curl_exec($curl); $html = str_get_html($response_string); //to fetch all hyperlinks from a webpage $links = array(); foreach($html->find('a') as $a) { $links[] = $a->href; } print_r($links); echo "<br />"; ?> SCRIPT 2 <?php //HALF WORKING include('simple_html_dom.php'); $url = 'http://php.net/manual-lookup.php?pattern=str_get_html&scope=quickref'; // WORKS ON URL //$url = 'https://yahoo.com'; // FAILS ON URL $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); $response_string = curl_exec($curl); $html = str_get_html($response_string); /* //to fetch all hyperlinks from a webpage $links = array(); foreach($html->find('a') as $a) { $links[] = $a->href; } print_r($links); echo "<br />"; */ // Hide HTML warnings libxml_use_internal_errors(true); $dom = new DOMDocument; if($dom->loadHTML($html, LIBXML_NOWARNING)){ // echo Links and their anchor text echo '<pre>'; echo "Link\tAnchor\n"; foreach($dom->getElementsByTagName('a') as $link) { $href = $link->getAttribute('href'); $anchor = $link->nodeValue; echo $href,"\t",$anchor,"\n"; } echo '</pre>'; }else{ echo "Failed to load html."; } ?> Don't forget my previous post! Cheers!
  4. I did a search on the php manual for str_get_html to be sure what the function does. But, I am shown no results. And so, I ask: Just what does it do ?
  5. I am told: "file_get_html is a special function from simple_html_dom library. If you open source code for simple_html_dom you will see that file_get_html() does a lot of things that your curl replacement does not. That's why you get your error." Anyway, folks, I really don't wanna be using this limited capacity file_get_html() and so let's replace it with cURL. I tried my best in giving a shot at cURL here. What-about you ? Care to show how to fix this thingY ?
  6. UPDATE: I have been given this sample code just now ... Possible solution with str_get_html: $url = 'https://www.yahoo.com'; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); $response_string = curl_exec($curl); $html = str_get_html($response_string); //to fetch all hyperlinks from a webpage $links = array(); foreach($html->find('a') as $a) { $links[] = $a->href; } print_r($links); echo "<br />"; Gonna experiment with it. Just sharing it here for other future newbies!
  7. I just replaced: //$html = file_get_html('http://nimishprabhu.com'); with: $url = 'https://www.yahoo.com'; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); $html = curl_exec($curl); That is all! That should not result in that error! :eek:
  8. Php Buddies, What I am trying to do is learn to build a simple web crawler. So at first, I will feed it a url to start with. It will then fetch that page and extract all the links into a single array. Then it will fetch each of those links pages and extract all their links into a single array likewise. It will do this until it reaches it's max link deep level. Here is how I coded it: <?php include('simple_html_dom.php'); $current_link_crawling_level = 0; $link_crawling_level_max = 2 if($current_link_crawling_level == $link_crawling_level_max) { exit(); } else { $url = 'https://www.yahoo.com'; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); $html = curl_exec($curl); $current_link_crawling_level++; //to fetch all hyperlinks from the webpage $links = array(); foreach($html->find('a') as $a) { $links[] = $a->href; echo "Value: $value<br />\n"; print_r($links); $url = '$value'; $curl = curl_init($value); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); $html = curl_exec($curl); //to fetch all hyperlinks from the webpage $links = array(); foreach($html->find('a') as $a) { $links[] = $a->href; echo "Value: $value<br />\n"; print_r($links); $current_link_crawling_level++; } echo "Value: $value<br />\n"; print_r($links); } ?> I have a feeling I got confused and messed it up in the foreach loops. Nestled too much. Is that the case ? Hint where I went wrong. Unable to test the script as I have to first sort out this error: Fatal error: Uncaught Error: Call to a member function find() on string in C:\xampp\h After that, I will be able to test it. Anyway, just looking at the script, you think I got it right or what ? Thanks
  9. I would appreciate anyone's replies on my previous 2 posts since they have different codes and I want to know why they are not working.
  10. Ok. I tried another ... <?php /* Using PHP's DOM functions to fetch hyperlinks and their anchor text */ $dom = new DOMDocument; $dom->loadHTML(file_get_contents('https://stackoverflow.com/questions/50381348/extract-urls-anchor-texts-from-links-on-a-webpage-fetched-by-php-or-curl/')); // echo Links and their anchor text echo '<pre>'; echo "Link\tAnchor\n"; foreach($dom->getElementsByTagName('a') as $link) { $href = $link->getAttribute('href'); $anchor = $link->nodeValue; echo $href,"\t",$anchor,"\n"; } echo '</pre>'; ?> I get error: Warning: DOMDocument::loadHTML(): Tag header invalid in Entity, line: 185 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 187 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag g invalid in Entity, line: 187 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 187 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 187 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag ellipse invalid in Entity, line: 187 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 187 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag main invalid in Entity, line: 190 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag section invalid in Entity, line: 191 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag header invalid in Entity, line: 192 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag article invalid in Entity, line: 195 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag footer invalid in Entity, line: 322 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag article invalid in Entity, line: 323 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 325 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 326 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 327 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 328 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 332 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 333 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 334 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 335 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 336 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 337 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag lineargradient invalid in Entity, line: 338 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 339 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 340 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 341 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 342 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 343 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 344 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 346 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag lineargradient invalid in Entity, line: 347 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 348 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 349 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 350 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 351 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 353 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag lineargradient invalid in Entity, line: 354 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 355 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 356 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 358 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag lineargradient invalid in Entity, line: 359 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 360 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 361 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 362 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 363 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag stop invalid in Entity, line: 364 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 366 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 367 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 368 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 369 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag nav invalid in Entity, line: 372 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 374 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 375 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 379 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 380 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 384 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 385 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 389 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 390 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 394 in C:\xampp\htdocs\cURL\crawler.php on line 7 Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 395 in C:\xampp\htdocs\cURL\crawler.php on line 7 Link Anchor https://fiverr.zendesk.com/hc/en-us/requests/new?ticket_form_id=64087 contact customer support //app.appsflyer.com/id346080608?pid=blockpage //app.appsflyer.com/com.fiverr.fiverr?pid=blockpage //www.linkedin.com/company/fiverr-com //twitter.com/fiverr //www.pinterest.com/fiverr //www.facebook.com/fiverr //www.instagram.com/fiverr Why all these errors ?
  11. saversites

    Recommend Me A Simple Php Crawler

    Bump!
  12. As you know, that code in my original post was for scraping all links found on Google homepage. Thanks for the hint. I have worked on it. But facing a little problem. The 1st foreach belongs to the original script to scrape the links from Google homepage. I now added 2 more foreach to scrape the outerhtml and innertext from each link in the hope that one of them 2 would scrape the links' anchor texts. But, I get a blank page now. Here is the code ... <?php # Use the Curl extension to query Google and get back a page of results $url = "http://forums.devshed.com/"; $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $html = curl_exec($ch); curl_close($ch); # Create a DOM parser object $dom = new DOMDocument(); # Parse the HTML from Devshed Forum. # The @ before the method call suppresses any warnings that # loadHTML might throw because of invalid HTML in the page. @$dom->loadHTML($html); # Iterate over all the <a> tags foreach($dom->getElementsByTagName('a') as $link) { # Show the <a href> echo $link->getAttribute('href'); echo "<br />"; foreach($dom->getElementsByTagName('p') as $outertml) { # Show the <outerhtml> echo $outerhtml->getAttribute('outerhtml'); echo "<br />"; foreach($dom->getElementsByTagName('p') as $innertext) { # Show the <innertext> echo $innertext->getAttribute('innertext'); echo "<br />"; } } } ?> I need the anchor texts of each link on the next line underneath their links. Where am I going wrong here ? Trying to scrape the links from here: http://forums.devshed.com/ Php Development Perl programming C Programming and so on ... Only scraping for learning purpose. Html looks like this: <h2 class="demi-title"><a class="forums" href="http://forums.devshed.com/perl-programming-6/">Perl Programming</a> <span class="viewing instruction">(16 Viewing)</span></h2> </div> <p class="forumdescription">Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.</p> Neither did this work as I still see a blank page. Nothing is getting scraped or echoed: <?php # Use the Curl extension to query Google and get back a page of results $url = "http://forums.devshed.com/"; $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $html = curl_exec($ch); curl_close($ch); # Create a DOM parser object $dom = new DOMDocument(); # Parse the HTML from Devshed Forum. # The @ before the method call suppresses any warnings that # loadHTML might throw because of invalid HTML in the page. @$dom->loadHTML($html); # Iterate over all the <a> tags foreach($dom->getElementsByTagName('a') as $link) { # Show the <a href> echo $link->getAttribute('href'); echo "<br />"; echo $link->nodeValue; } ?> Regards!
  13. Php Gurus, You know of any good php web crawler freeware/gpl, open source, etc. ? Might aswell checkout the source code and learn from there (cURL, DOM, etc. stuffs). Sphider is using deprecated stuffs and so not good.
  14. Php Buds, Here's the code, using DOM for grabbing links from google: <?php # Use the Curl extension to query Google and get back a page of results $url = "http://www.google.com"; $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $html = curl_exec($ch); curl_close($ch); # Create a DOM parser object $dom = new DOMDocument(); # Parse the HTML from Google. # The @ before the method call suppresses any warnings that # loadHTML might throw because of invalid HTML in the page. @$dom->loadHTML($html); # Iterate over all the <a> tags foreach($dom->getElementsByTagName('a') as $link) { # Show the <a href> echo $link->getAttribute('href'); echo "<br />"; ?> It echoes results sort of like this: https://www.google.com.com/webhp?tab=ww http://www.google.com.com/imghp?hl=bn&tab=wi http://maps.google.com.com/maps?hl=bn&tab=wl Now, I'd like to convert the above code so again using DOM it is able to extract all urls and their anchor texts from all links residing on any chosen webpage no matter what format the links are in. Formats such as: <a href="http://example1.com">Test 1</a> <a class="foo" id="bar" href="http://example2.com">Test 2</a> <a onclick="foo();" id="bar" href="http://example3.com">Test 3</a> The anchor texts should sit underneath each extracted url. And there should be a line in-between each listed item. Such as: http://stackoverflow.com<br> A programmer's forum<br> <br> http://google.com<br> A searchengine<br> <br> http://yahoo.com<br> An Index<br> <br> And so on. I'd also appreciate another version (not using DOM). This time a cURL version too. Which performs the same result. This cURL (not using DOM) did not exactly work as was intended: <?php /* $curl = curl_init('http://devshed.com/'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $page = curl_exec($curl); if(curl_errno($curl)) // check for execution errors { echo 'Scraper error: ' . curl_error($curl); exit; } curl_close($curl); $regex = '<\s*a\s+[^>]*href\s*=\s*[\"']?([^\"' >]+)[\"' >]'; if ( preg_match($regex, $page, $list) ) echo $list[0]; else print "Not found"; ?> Any chance I can this achieved with cURL (not using DOM) without the regex ? You know I dislike regex and prefer simplicity in coding. Nevertheless, from your end, I'd like to see a regex sample and another sample without regex. Oh by the way, I really prefer not to use limited functions such as the get_file() and the like. You know what I mean. Give us your best shots! Take care! Cheers!
×