problem with ereg and backslashes

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
mottwsc
Forum Commoner
Posts: 55
Joined: Sun Dec 23, 2007 8:01 pm

problem with ereg and backslashes

Post by mottwsc »

I'm allowing users to send an email as an invitation. I pre-fill it (using \n for new line), let them edit it and check if after that. I always get a negative response in the ereg when including \ in the string, and I can't figure out how to fix it. Any suggestions?

Code: Select all

 
$invitationClean = "Hello.\n\nYou are invited.";
if( !ereg("^([A-Za-z0-9',. -!\\]{0,250})+$", $invitationClean) )
{ echo "invitationClean - bad data<br>"; }
else
{ echo "invitationClean - OK data<br>"; }
 
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: problem with ereg and backslashes

Post by novice4eva »

Its not \ that's giving you the problem, i think it's with \n, so why don't you try

Code: Select all

 
if( !ereg("^([A-Za-z0-9',. -!\n\\]{0,250})+$", $invitationClean) )
 
mottwsc
Forum Commoner
Posts: 55
Joined: Sun Dec 23, 2007 8:01 pm

Re: problem with ereg and backslashes

Post by mottwsc »

Thanks, that helped with the \n problem.
Post Reply