You are here:  » Parsing only the url out of a full HREF


Parsing only the url out of a full HREF

Submitted by stwatkins on Tue, 2007-05-15 19:38 in

Hello everyone,

I was hoping someone could help out with this one. It may be possible that this can be done using regular expressions, but if there is an easier way using MP I could use some help.

I have a full HREF url like this <a href="http://www.yahoo.com">http://www.yahoo.com</a>

I would like to remove the <a href="http://www.yahoo.com"></a> parts and just have the url with no anchor code around it - so a parse routine that would take

This:
<a href="http://www.yahoo.com">http://www.yahoo.com</a>

and return this:

http://www.yahoo.com

Thanks in advance!!

Steve

Submitted by support on Wed, 2007-05-16 08:17

Hello Steve,

PHP's strip_tags() function works fine in this scenario...

<?php
  $html 
'<a href="http://www.yahoo.com">http://www.yahoo.com</a>';
  
$html strip_tags($html);
  print 
$html;
?>

Simply incorporate strip_tags() where necessary in your script and it should do the trick...

Cheers,
David.