Welcome to WebmasterWorld Guest from 107.22.87.205

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)

10+ Year Member



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 Jun 16, 2004 (gmt 0)

10+ Year Member



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 Jun 16, 2004 (gmt 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 Jun 16, 2004 (gmt 0)

10+ Year Member



thanks
i always forget about that
10:26 am on Jun 16, 2004 (gmt 0)

10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month