Pattering matching /regular expression help

Events happening in the community are now at Drupal community events on www.drupal.org.
alanburke's picture

Hi all,

I need to do a simple filter to remove some odd character that get imported into my nodes [bulk import].

The characters are

ºº

and I need to replace them with a
<br />.

I've built a little filter module, which will do the trick, but my regex skills are , well, non existent.

I've tried

<?php
$text
= eregi('ºº','<br />',$text);
?>

to no avail.

Can anybody help?

Alan

Comments

try this

john morahan's picture

<?php
$text
= preg_replace('/ºº/', '<br />', $text);
?>

No dice...

alanburke's picture

Hi John,
Thanks for the quick response.

No luck with that, I'm afraid.

I'm pretty sure the rest of the module is functioning.
If I try a simpler preg_replace [with a word in the text, for example], it seems to work fine.

For whatever reason, it doesn't 'see' those characters, and doesn't remove them.

Alan

Maybe a character set issue

john morahan's picture

Maybe a character set issue - are you saving your module file as UTF-8?

Hmm

alanburke's picture

Maybe that's the issue.
I'll look into it further.

We're in the presence of greatness!

alanburke's picture

Well done John,

My module file wasn't UTF-8 - it is now!

All good, thanks a million!

Alan

I can't tell, what are those

stella's picture

I can't tell, what are those characters?

No idea!

alanburke's picture

I don't even know what they're called myself!

Speed

jbligh's picture

The simpler str_replace function would be faster than a full regular expression assuming it can handle the character encoding issue.

Alan: one of these days

scor's picture

Alan: one of these days you'll get on IRC and understand what you are missing :p

Ireland

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: