ryanfait Posted May 16, 2008 Share Posted May 16, 2008 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 More sharing options...
effigy Posted May 16, 2008 Share Posted May 16, 2008 /<a[^>]+href="(.+?)"/ Link to comment https://forums.phpfreaks.com/topic/105881-pulling-a-url-from-an-anchor/#findComment-542853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.