Can't replace + with ereg_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

Can't replace + with ereg_replace

Post by dimitris »

in order to pass names from page to page via get but i have problems!

I succeded running first this code:
їcode]$loc=ereg_replace(" ","+",$loc);ї/code]
but when i use
їcode]$plus='+';
$loc=ereg_replace($plus, " ",$loc);ї/code]
or

$loc=ereg_replace("+", " ",$loc);

i get this error:
Warning: Invalid preceding regular expression in /home/greeceqt.com/www/locations_islands.php on line 15

What is wrong?I guess that the problem is + which may be confused with its operator ability!
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

try

Code: Select all

$loc=ereg_replace("\+", " ",$loc);
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

Post by dimitris »

Wayne wrote:try

Code: Select all

$loc=ereg_replace("\+", " ",$loc);
OK it worked! I also found that

Code: Select all

$loc=str_replace("+", " ",$loc);
works too!
Post Reply