homepage Welcome to WebmasterWorld Guest from 54.242.231.109
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
ereg_replace problem
ereg_replace(): REG_BADRPT
WhosAWhata




msg:1267850
 1:19 am on Jun 16, 2004 (gmt 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

 

Hanu




msg:1267851
 1:39 am on Jun 16, 2004 (gmt 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.

bonanza




msg:1267852
 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('%',' ','{','}','~','<','>','!','"','\$','&','\+',',','/',':',';','=','\?','@');

WhosAWhata




msg:1267853
 3:25 am on Jun 16, 2004 (gmt 0)

thanks
i always forget about that

dcrombie




msg:1267854
 10:26 am on Jun 16, 2004 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved