Re: Apostrophe in preg_match?

From: Date: Fri, 30 Aug 2002 23:28:15 +0000
Subject: Re: Apostrophe in preg_match?
Groups: php.general 
Request: Send a blank email to php-general+get-114718@lists.php.net to get a copy of this message
>I'm trying to get an apostrophe (and a dash, as well) to be >included in a preg_match expression, but I don't know how to escape the >characters. The dash has to come "last" in your [] grouping: [!a-zA-Z-] ^ | This will work. The ' is a matter of counting how many \s PHP wants and how many Perl wants. Inside "", PHP doesn't need ' escaped at all. Perl needs a \, but in PHP, you need \\ to get a \ inside the quotes. So I'm betting it's more like: "^[!a-zA-Z\\'-]$" NOTE: I'm not sure what you think ^ at the end of the [] means, but I don't think it's what you want... I dunno what you were trying to do with the / in there... If you just want / as a character, I know PHP doesn't need any escaping, but God only knows about the Perl part of it. > ><?php >if (preg_match("^[!a-zA-Z-/\\\'/]^", $_POST['ssname'])) die >("<h5>Numbers and special characters not allowed in >'Surname'<br><br> > Click 'Back' on your browser to re-enter >information.</h5>"); > >?> >Any help will be greatly appreciated. > >Tia, >Andre -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#114718) next »