0

I would like to find a match in html source code for the following data:

<meta property="al:android:url" content="fb://profile/123123121123" />

using preg_match_all(); I am not sure how to write the code.

after getting the answer to this : preg_match_all('/]*)\"/', $html, $matches);

it's not working, it's returning an empty set.

this is my code:

 $ret = array();

    $matches = array();
    // die();
    $url = 'https://www.facebook.com/' . $fanpage_name;
    // die($url);
    $context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0')));
    for($a = 0; $a < $no_of_retries; $a++){
        $like_html = file_get_contents($url, false, $context);

               preg_match_all('/<meta property=\"al:android:url\" content=\"([^">]*)\"/', $like_html, $matches);


        if(empty($matches[1])){
            // failed to fetch any fans - convert returning array, cause it might be not empty
            echo "test    ";
            return array_keys($ret);
        }else{
            // merge profiles as array keys so they will stay unique
            $ret = array_merge($ret, array_flip($matches[1]));
        }
        // don't get banned as flooder
        usleep($pause);
    }
    return array_keys($ret);
3
  • You should use an HTML/XML parser, stackoverflow.com/questions/3577641/…. Commented Aug 4, 2015 at 14:19
  • simple: you DON'T. regexes + html = suicide. use a DOM parser. Commented Aug 4, 2015 at 14:19
  • simplehtmldom.sourceforge.net would be the best thing for that. It's easy to use and has good documentation Commented Aug 4, 2015 at 14:22

1 Answer 1

1

If you are interested in the attribute "content"

preg_match_all('/<meta property=\"al:android:url\" content=\"([^">]*)\"/', $html, $matches);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.