Regexp whining

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Regexp whining

Post by Shendemiar »

I'm ashamed but i'm too stupid to learn regexp properly.

I'd like to remove all the links from html, but leave the text, underlined.

I need to replace all "<A HREF_anything_until_>" with <U> with regexp i hope someone can provide.

The closing </a> i can replace with str_replace.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

the following code i got from this forum.. so you should be able to find it too....

Code: Select all

$url = 'http://cnn.com';
$document = @file_get_contents($url);
preg_match_all('/&lt;a(.*?)&gt;(.*?)&lt;\/a&gt;/i', $document, $matches);
print_r($matches);
http://www.regularexpressions.info/
http://www.samuelfullman.com/team/php/t ... ster_p.php
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

Thanks. Made this from the above.

Code: Select all

function links_off($buffer)
&#123;
  // Poista Linkit
  $a  = preg_replace("/<a(.*?)>/i", "<U>", $buffer);
  $a  = preg_replace("/<\/a>/i", "</U>", $a);
  return $a;
&#125;
Post Reply