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.

Confusion over regexp ".test($value)"

Discussion in 'PHP' started by PaddyL, May 3, 2008.

  1. #1
    I am an ex-programmer, so please forgive what may be a simple question.

    In one of my old PHP programs, I came across the following syntax:

    if ( /<a\s+href=/i.test( $value ) )
    PHP:
    I immediately recognised the format as a regular expression, and understood what it meant. However, this format is something I just don't remember (obviously I did, once, because that was my program that no one else has had access to). I only remember using the function preg_match for this type of test.

    On trying to refresh my memory, I've been perusing the on-line PHP manual for ages, and just can't find where the manual documents this.

    Would some kind soul please point me to the correct manual page in the PHP manual for this test function?
     
    PaddyL, May 3, 2008 IP
  2. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i know there is ereg and eregi...what you just showed, I've never seen personally.
     
    NatalicWolf, May 3, 2008 IP
  3. PaddyL

    PaddyL Active Member

    Messages:
    69
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    50
    #3
    The funny thing is, I must have seen it once upon a time to have been able to program this (and it works... I've checked).

    But where did I see it? I hope someone will answer this.
     
    PaddyL, May 4, 2008 IP
  4. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That isn't PHP my good man, that is javascript;) I simply put the "/<a\s+href=/i.test" into google and second result shows it is javascript.

    http://svn.openqa.org/fisheye/browse/selenium/trunk/src/main/resources/core/xpath/util.js?r=2044
    if (!/^href$/i.test(nodeName)) return nodeValue;

    I'm assuming you're using echo and $value is the thing you are testing inside JS.
     
    NatalicWolf, May 4, 2008 IP
    PaddyL likes this.
  5. PaddyL

    PaddyL Active Member

    Messages:
    69
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    50
    #5
    OMG! :eek: You are so right!

    I missed the heredoc that surrounds the code! (I used heredoc instead of echo.)

    I also see that when I copied the code (by hand, not cut-and-paste), I inserted a $ before the "value". Sorry. :eek::eek::eek:

    Thank you for this. Boy, have I wasted my time searching in the PHP manual!
     
    PaddyL, May 5, 2008 IP