How to extract all URL’s from webpage in an array an see if certain value is there [migrated]


I am trying to extract all the links from a webpage and put them into an array that I can then compare values with to see if there is a match. The problem that I’m having is I cannot seem to get the values into an array. I am able to see all the links and I see that there is a match with the one I’m trying to compare with but it’s not recognizing that it’s there. My code is as follows. Any help would be greatly appreciated.

        $content = file_get_contents("sample_url");
        $content = strip_tags($content,"<a>");
        $subString = preg_split("/</a>/", $content);
        $items = array();
        foreach ( $subString as $val ){
            if( strpos($val, "<a href=") !== FALSE ) {
            $val = preg_replace("/.*<as+href="/sm","",$val);
            $val = preg_replace("/".*/","",$val);
            $items[] = $val;
            var_dump($val."<br />");


        if (in_array($testing_link, $items, true)) {
            echo 'It is here!';
        else {
            echo 'it is NOT here :( ';
wp_dev99 4 months 0 Answers 9 views 0

Leave an answer