user375566
user375566

Reputation:

preg_match expression help

Can't seem to figure this one out. Just trying to preg match for a specific variable name in a link URL:

<a href="http://something.com?variable=name">GenericLink</a>

How do I get the variable=name out of this?

Thanks!

Upvotes: 1

Views: 131

Answers (1)

Mark Baker
Mark Baker

Reputation: 212412

Extract the whole url and then use parse_url();

$str = '<a href="http://something.com?variable=name">GenericLink</a>';

preg_match('/href="([^"]*)/i',$str,$matches);
var_dump(parse_url($matches[1]));

Upvotes: 3

Related Questions