Welcome to WebmasterWorld Guest from 54.242.224.250

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

ereg_replace problem

ereg_replace(): REG_BADRPT

     
1:19 am on Jun 16, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 12, 2003
posts:454
votes: 0


i have code like this

function myEncode($ff){
$un = array('%',' ','{','}','~','<','>','!','"','$','&','+',',','/',':',';','=','?','@');
$nn = array('%25','%20','%7b','%7d','%7e','%3c','%3e','%21','%22','%24','%26','%2b','%2c','%2f','%3a','%3b','%3d','%3f','%40');
foreach($un as $k => $v) {
$ff = ereg_replace($v,$nn[$k],$ff);
}
return $ff;
}

it echo's
Warning: ereg_replace(): REG_BADRPT

1:39 am on June 16, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 8, 2003
posts:548
votes: 0


Have a look at urlencode().

Your solution is kind of an 'abuse' of ereg_replace() which accepts regular expressions and not plain strings. In regular expressions some characters have a special meaning. For example, a curly bracket introduces a repetition. But it needs to be followed by a number and a closing curly bracket. Hence the error message.

1:42 am on June 16, 2004 (gmt 0)

Junior Member

joined:Apr 27, 2003
posts:131
votes: 0


Some characters have special meaning in regular expressions.
Escape them with a backslash to tell regexp that you mean just the character.

I think I've got them all below...

$un = array('%',' ','{','}','~','<','>','!','"','\$','&','\+',',','/',':',';','=','\?','@');

3:25 am on June 16, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 12, 2003
posts:454
votes: 0


thanks
i always forget about that

dcrombie

10:26 am on June 16, 2004 (gmt 0)

Inactive Member
Account Expired

 
 


str_replace is probably the best option here - or urlencode if that achieves what you want.