Page 1 of 1

Regexp whining

Posted: Thu Dec 09, 2004 11:44 am
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.

Posted: Thu Dec 09, 2004 11:53 am
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

Posted: Thu Dec 09, 2004 12:03 pm
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;