954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

preg_replace shortens string off

Hi all,

I want to replace these charachters:

Æ,Ø,Å,æ,ø,å, with,
AE,OE,AA,ae,oe,aa

I thoght I could use preg_replae this way to accomplish that, but if i write this word in the form: "Bælter" - All that is left to be inserted into the DB is "B" - So I am removing everything from the special charachter away from the string...

This is what i have:

$search = array('/Æ/', '/Ø/', '/Å/', '/æ/', '/ø/', '/å/', '/ /');
$replace = array('AE', 'OE', 'AA', 'ae', 'oe', 'aa', '-');
$vare_gruppe_url = preg_replace($search,$replace,$vare_gruppe_url);


I am using utf-8 - and have read that preg_replace doesnt work too well with 2 byte charachters, i think that was how it was described..

Can someone point out why this is happening and not working?

Basically what i want is this:

"Bælter" should become "Baelter".

Regards, Klemme

klemme
Posting Whiz in Training
265 posts since Mar 2011
Reputation Points: 18
Solved Threads: 7
 

According to the third comment here , you should use the 'u' modifier.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Right, How do I implement the 'U' modifier in the pattern, have you any experience with that?

I have tried it different ways, with no succes so far :-/

$search = array('/Æ/', '/Ø/', '/Å/', '/æ/', '/ø/', '/å/', '/ /');
$replace = array('AE', 'OE', 'AA', 'ae', 'oe', 'aa', '-');
$vare_gruppe_url = preg_replace($search,$replace,$vare_gruppe_url);
klemme
Posting Whiz in Training
265 posts since Mar 2011
Reputation Points: 18
Solved Threads: 7
 
$search = array('/Æ/u', '/Ø/u', '/Å/u', '/æ/u', '/ø/u', '/å/u', '/ /');
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
$search = array('/Æ/u', '/Ø/u', '/Å/u', '/æ/u', '/ø/u', '/å/u', '/ /');
$replace = array('AE', 'OE', 'AA', 'ae', 'oe', 'aa', '-');
$vare_gruppe_url = preg_replace($search,$replace,$vare_gruppe_url);


It should be called preg_remove..

I am left with only B if $vare_gruppe_url = "Bælter"..

Any help is appreciated!

klemme
Posting Whiz in Training
265 posts since Mar 2011
Reputation Points: 18
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: