Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 893903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:17:42+00:00 2026-05-15T14:17:42+00:00

<?php $url=’http://edition.cnn.com/?fbid=4OofUbASN5k’; $var = fread_url($url);// function calling to get the page from curl $search

  • 0
<?php
$url='http://edition.cnn.com/?fbid=4OofUbASN5k';

$var = fread_url($url);// function calling to get the page from curl
$search = array('@<script[^>]*?>.*?</script>@si');  // Strip out javascript
$var = preg_replace($search, "\n", html_entity_decode($var)); // Strip out javascript

$linklabel = array();
$link = array();
$dom = new DOMDocument($var);
@$dom->loadHTML($var);
$xpath = new DOMXPath($dom);// Grab the DOM nodes 

foreach($xpath->find('a') as $element) {
    array_push($linklabel, $element->innerText);
    print $linklabel;
    array_push($link, $element->href);
    print $link.'<br>';
}


function fread_url($url) {
    if(function_exists("curl_init")) {
        $ch = curl_init();
        $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; ".
                "Windows NT 5.0)";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
        curl_setopt( $ch, CURLOPT_HTTPGET, 1 );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
        curl_setopt( $ch, CURLOPT_URL, $url );

        curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
        $html = curl_exec($ch);
//print $html;//printing the web page.
        curl_close($ch);
    }
    else {
        $hfile = fopen($url,"r");
        if($hfile) {
            while(!feof($hfile)) {
                $html.=fgets($hfile,1024);
            }
        }
    }
    return $html;
}

i need to seperate links and link labels into two seperate arrays. i followed several forums and made a code, but is getting error. i don’t know about the find function used in the code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:17:43+00:00Added an answer on May 15, 2026 at 2:17 pm

    Several problems, mainly calls to inexistent functions and references to inexistent properties. Correct version:

    <?php
    $var = <<<EOD
    <html>
    <a href="sdfgs">sdfd</a>
    </html>
    EOD;
    
    $dom = new DOMDocument();
    @$dom->loadHTML($var);
    $xpath = new DOMXPath($dom);
    
    foreach($xpath->query('//a') as $element) {
         $linklabel[] = $element->textContent;
         $link[] = $element->getAttribute("href");
    }
    var_dump($linklabel);
    var_dump($link);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

regulars question :P Current URL http://domain.com/index.php http://domain.com/index.php?page=submit-hosting http://domain.com/index.php?page=popular-hosting How write my .htaccess to make
function checkSession(){ $.ajax({url: session.php, success: function(data){ if( data == 1){ var postFilen = 'msg.php';
Let's say my current url is http://domain.com/category/clothing-personal-items/&page=3 I used $_SERVER[REQUEST_URI] to get current request
Why is parse_url returning empty string in this case? <?php $url='www.example.com'; $var= parse_url($url,PHP_URL_HOST); print_r($var);
I want to get Get Domain from URL and be output: http://www.domain.com/ I found
I am trying to get the requested URL from PHP. The URL is like
$.ajax({ type: 'get', url: 'message.php', data: 'msg=' + msg + '&fromname=' + fromname +
Hi I writed a test code as below. <?php $url = 'http://localhost/events/result/cn_index.php?login'; print_r(parse_url($url)); echo
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I was developing a web crawler when I noticed this. URL 1: http://www.techwyse.com/services/ URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.