Page 4 of 4 FirstFirst ... 234
Results 31 to 34 of 34

Thread: Help with a preg_match

  1. #31
    Join Date
    Dec 2008
    Posts
    48
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    ok finnaly found another way that this wont work, should be simple. Some sites use:

    Code:
    <a href='http://www.site.com/OtherMethods.php'>
    instead of

    Code:
    <a href="http://www.site.com/OtherMethods.php">
    ' for "

    how should we predict this aswell?

  2. #32
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    try this:
    Code:
    '/(<a.*?href=\"|\')(.*?)(\/\"|\'|\")/is'
    Quote Originally Posted by nicmo View Post
    regex is a little too much info for me right now, hopefully i will grasp it soon.
    regex can be a bit complicated. What makes it more complicated is that there is seldom a reason to use it, so it's easy to get out of practice. It is also best to use it as little as possible since it is processor heavy.

    getting back to the regex at hand though. I really am only barely grasping at what you are trying to do, but it seems well enough that I am able to be of some use to you When using href it is best to use the double quotes so as to avoid potential errors. I believe the errors I speak of have to do with relative versus absolute urls, but this has not been an issue for long enough that I forget exactly what the problem was with using single quotes with href.

    Let me know if the regex I posted above fails and with what and we will address that when the time comes.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #33
    Join Date
    Dec 2008
    Posts
    48
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    that kinda did its job but the array was getting all messed up with the extra ' all over the place. so i did this:

    PHP Code:
    $result str_replace("'"'"'$result); 
    just before preg_match_all, seems it should be fixed. For now...

  4. #34
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    This time I found an error. try the following instead
    PHP Code:
        preg_match_all ('/(<a.*?href=\"|<a.*?href=\')(.*?)(\/\"|\'|\")/is'$result$matches); 
    otherwise
    Code:
    <a "http://www.site.com/OtherMethods.php">
    will match.

    The pcre created thus far could probably still be improved in several different ways yet, so if you see ways that it needs to be modified yet just let me know.
    To choose the lesser of two evils is still to choose evil. My personal site

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
  •