filtering links to a certain website by custom module (regular expressions problem)
Hi
I want to make a filter module, which will be deleting links to one website (ebay auctions), but let's say it's http://www.example.com/something-after-ending-slash. I already made up a new module, changing a bit urlfilter.module, but I have a problem with regular expressions, because It's deleting example.com but leaves http://www. and everything after ending domain name slash /something-after-ending-slash
Please take a lok at my code and help me.
Most important is this piece of code:
<?php
$text = preg_replace("'(example.com)'i", '', $text);
?>So let's say someone posts link:
http://www.example.com/something-after-ending-slash
after filtering that's how it looks like:
http://www. /something-after-ending-slash
I'm attaching also full module code (may be useful for further development):
<?php
// $Id: linkfilter.module,v 1.18.2.5 2006/06/08 16:07:07 unconed Exp $
function linkfilter_help($section) {
switch ($section) {
case 'admin/help#linkfilter':
$output = '<p>'. t('The linkfilter module automatically cut offs text web addresses to bloody auctions.') .'</p>';
$output .= t('<p>Use Input Formats to enable the Linkfilter</p>
<ol>
<li>Select an existing Input Format or add a new one</li>
<li>Configure the Input Format</li>
<li>Enable URL filter and Save configuration</li>
<li>Rearrange the weight of the URL filter depending on what filters exist in the format</li>
</ol>');
$output .= t('<p>You can</p>
<ul><li>enable the linkfilter in an input format from <a href="%admin-filters">administer >> Input Filter</a>.</li></ul>', array('%admin-filters' => url('admin/filters')));
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%linkfilter">URL filter page</a>.', array('%linkfilter' => 'http://www.drupal.org/handbook/modules/linkfilter/')) .'</p>';
return $output;
case 'admin/modules#description':
return t('Cut off links to bloody auctions.');
}
}
function linkfilter_filter_tips($delta, $format, $long = false) {
return t('bloody auctions links are cut off');
}
function linkfilter_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(0 => t('Link filter'));
case 'description':
return t('Cut off bloody links to the auctions.');
break;
case 'process':
$text = ' ' . $text . ' ';
$text = preg_replace("'(ebay.com)'i", '', $text);
return $text;
default:
return $text;
}
}
?>
Im really confused about
Im really confused about those regular expressions, I've tried almost everything :-(