Jump to content

Pulling a URL From an Anchor


ryanfait

Recommended Posts

I'm trying to pull a URL from an HTML anchor. The following regex used with preg_replace works for everything except <a href="/">. I just need it to grab the / from inside the href="". It correctly pulls out <a href="/page/">.

 

<?php
$pull_address = "/<a[\s]{1}href\=\"([\w\.0-9\/\-\%\?\=^#]{1}[\w\.0-9\/\-\%\?\=&;]+)(#[\w\.0-9\/\-\%\?\=&;]*)?\"(.*)?>/";

$loc = preg_replace($pull_address, "$1", $anchor);
?>

Link to comment
https://forums.phpfreaks.com/topic/105881-pulling-a-url-from-an-anchor/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.