Extract a parameter from URL using a regex in PHP -


i have number of links like:

<a href="http://url.com/?foo=bar&p=20" title="foo">foo</a> <a href="http://url2.com/?foo=bar&p=30" title="foo">foo</a> 

i'm trying extract parameter p each href found. in case have end result array array (20, 30).

what regex this? thanks.

don’t try parse html regular expressions; use html parser php’s dom library or php simple html dom parser instead. parse url parse_url , query string parse_str.

here’s example:

$html = str_get_html('…'); $p = array(); foreach ($html->find('a[href]') $a) {     parse_str(parse_url($a->getattribute('href'), php_url_query), $args);     if (isset($args['p'])) $p[] = $args['p']; } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -