SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: regex

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Whistler, Canada
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regex

    Hi all,

    I made the following regex:

    Code:
    <td([^>]*?)class=\\042timedist\s?ul\\042>(.*?)</td>
    I'm using Regulator to test it, and there it works fine on the input file.

    However, when I put it in my PHP script, it doesn't return anything. I'm positive the input is the very same in both cases. This is in my PHP file:

    PHP Code:
    preg_match_all("~<td([^>]*?)class=\\042timedist\s?ul\\042>(.*?)</td>~"$html$matches); 
    Where $matches returns an empty array.

    Anyone who can help me out here?

    Cheers,
    Pepe

  2. #2
    ::==:: Bonzo_CS's Avatar
    Join Date
    Dec 2003
    Location
    (Cardiff Wales)
    Posts
    747
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if this helps as I don't know what yur after exactly, but this works:

    $pattern = '/(td\sclass=[\s\"\'])(.*?)([\"\']?)(.*?)(>)/si';
    $info = 'Testing 123 : <td class="042timedist?ul\042"">Some data here</td>';
    $result = preg_match_all($pattern, $info, $matches);

  3. #3
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you please post an input example which works in Regulator and which doesn't in your script?

    By the way: why do you use the octal representation instead of the literal character?
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guessing here, but:
    PHP Code:
    preg_match_all('~<td([^>]*?)class="timedist\s?ul">(.*?)</td>~'$html$matches); 

  5. #5
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, but
    Code:
    preg_match_all('~<td([^>]*?)class="timedist\s?ul">(.*?)</td>~', $html, $matches); 
    preg_match_all("~<td([^>]*?)class=\\042timedist\s?ul\\042>(.*?)</td>~", $html, $matches); 
    preg_match_all('~<td([^>]*?)class=\042timedist\s?ul\042>(.*?)</td>~', $html, $matches);
    are all the same and work for
    Code:
    $html = '<td blah="blah" class="timedist ul">test</td>';
    so it has to be something else
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •