DotDragnet
May 23, 2012, 05:10:01 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Preg Replace  (Read 861 times)
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« on: July 18, 2010, 11:03:15 AM »

a-zA-Z0-9@ :{}_.-/

I need those characters to be allowed only, but am having problems with the forward slash.

here's my code:

return preg_replace("/[^a-zA-Z0-9@ :{}_.-/]/i", "", urldecode($address));

How do I make it use the forward slash and not see it as a limiter (if that makes sense).

Thanks all!
Logged
JasonD
Global Moderator
Hero Member
*****
Posts: 550



View Profile Awards
« Reply #1 on: July 18, 2010, 11:31:20 AM »

Escape the / and the - with a \

Do you really need urldecode?
Logged
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« Reply #2 on: July 19, 2010, 12:59:19 PM »

jason - very many thanks, you got me out of a bind.

Is there a list of characters that should be escaped at all times?
Logged
JasonD
Global Moderator
Hero Member
*****
Posts: 550



View Profile Awards
« Reply #3 on: July 19, 2010, 03:24:03 PM »

The preg_quote() manual page should have a list, although not all need escaping at all times, the {} when in [] don't, for example.
Logged
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« Reply #4 on: March 01, 2011, 07:12:54 PM »

Back on this, with a slight problem.

I now need to include all the extended characters used in other languages, eg
á à ø and all the rest.  Any idea how to do that?  Been searching google fruitlessly.
Thank You in advance.
Logged
JasonD
Global Moderator
Hero Member
*****
Posts: 550



View Profile Awards
« Reply #5 on: March 01, 2011, 11:49:16 PM »

\pL

http://uk.php.net/manual/en/regexp.reference.unicode.php

Couldn't find the manual in Google eh?
Logged
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« Reply #6 on: March 02, 2011, 09:15:25 AM »

Thanks Jason - I didn't bother with that as the webpages are iso-8859-1 and the db is latin1_swedish_ci.
This appears to be utf-8 ?  I'll test it.
Logged
JasonD
Global Moderator
Hero Member
*****
Posts: 550



View Profile Awards
« Reply #7 on: March 02, 2011, 01:32:13 PM »

http://en.wikipedia.org/wiki/ISO/IEC_8859-1

[a-zA-ZÀ-ÖØ-öø-ÿ]

etc. Just be sure that your php is saved as iso-8859-1 too or use the \xXX form.

If you're doing much in non-English then utf-8 would be better in the long term. If the Norwegians want to use their proper alphabet the Welsh won't be too far behind.
Logged
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« Reply #8 on: March 02, 2011, 03:51:08 PM »

LOL, thanks boyo. 

Appreciated.  Cheers.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!