Solved

get all href values in string

Posted on 2009-05-11
5
297 Views
Last Modified: 2012-05-06
i have this string:

<p>this is a string with one <a href="http://www.velodays.com/" title="">link</a> here and another <a href="http://www.seandelaney.co.uk/" title="">link</a> here.</p>

I want to remove all <a></a> tags but keep the href values.

So for example the above would output as:

<p>this is a string with one http://www.velodays.com/ here and another http://www.seandelaney.co.uk/ here.</p>

I tried using strpos and substr but couldnt manage a solution.

Can somebody please correct me and help me get a working solution ?
0
Comment
Question by:ellandrd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24357349
This regexp might help:
$str = '<p>this is a string with one <a href="http://www.velodays.com/" title="">link</a> here and another <a href="http://www.seandelaney.co.uk/" title="">link</a> here.</p>';
$str = preg_replace('@<a\s+href="([^"]+)"[^>]*>[^<>]*</a>@i','$1',$str);
echo $str;

Open in new window

0
 
LVL 16

Author Comment

by:ellandrd
ID: 24362896
that works fine but how do i make it work if the link format is:

<a title="" href=""></a>
0
 
LVL 39

Assisted Solution

by:Roger Baklund
Roger Baklund earned 500 total points
ID: 24362961
Try this regexp then:
$str = preg_replace('@<a\s+.*href="(.*)".*>.*</a>@iU','$1',$str);

Open in new window

0
 
LVL 16

Author Closing Comment

by:ellandrd
ID: 31580243
thank you - both work perfect!
0
 
LVL 16

Author Comment

by:ellandrd
ID: 24363743
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question