1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help with PREG_MATCH

Discussion in 'Programming' started by tyankee, May 4, 2014.

  1. #1
    can someone help explain to me in simple English what this statement does:

    if(!preg_match("/^[a-zA-Z0-9+\/ _-]+$/D", $v))


    i would like to allow for the inclusion of the character '$' in the string as it's not now allowed and i do not understand what this statement is allowing or not allowing..

    a step by step breakdown would be real helpful.. maybe starting out with:

    if not preg_match allow characters a-z, 0-9, etc.. something like that..
     
    tyankee, May 4, 2014 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,455
    Likes Received:
    1,747
    Best Answers:
    31
    Trophy Points:
    475
    #2
    qwikad.com, May 4, 2014 IP
    tyankee likes this.
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    $ is restricted, to include it you have to escape it with a backslash just like the forward slash was. The \/ in there is the backslash escaping the forward slash so you can use it... just like you would with \\, \^, \[, \], etc, etc... Any time you want a literal version of one of the regex control characters, you escape it with a forward slash. I think that your "plus" should also be escaped in that since it too is a control character.

    if (!preg_match("/^[a-zA-Z0-9\+\/ _-\$]+$/D", $v))

    Should do what you are asking.
     
    deathshadow, May 4, 2014 IP
    tyankee likes this.
  4. tyankee

    tyankee Well-Known Member

    Messages:
    1,023
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    150
    #4
    ok, i think it get then that the characters within the [] brackets are what's allowed??? then after the ] what does the +$/D do??
     
    tyankee, May 4, 2014 IP
  5. tyankee

    tyankee Well-Known Member

    Messages:
    1,023
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    150
    #5
    tyankee, May 4, 2014 IP