Regular expression help

Discussion in 'PHP' started by squishi, Aug 16, 2009.

  1. #1
    $this->post['message'] = preg_replace('!(\\[url(\\[img)?|\\[email|\\[img)(.*)((\\[\/img\\])?\\[\/url\\]|\\[\/email\\]|\\[\/img\\])|<a[^>]*(http|www|mailto)(.*)</a>|(http:\/\/)?www(.*)[\s]\b|<img[^>]*(src|border|title)(.*)(</img>|\/>)|[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b!siU', construct_phrase(), $this->post['message'].' ');
    PHP:
    Regular expressions are a book with seven seals to me. :(

    The above expression filters all links and replaces them with the result of the construct_phrase function.

    Instead of filtering for all urls ("(http:\/\/)?www(.*)")
    I would love to exclude my own domain from that filter.
    So if the link matches (www.)mydomain.com, the construct_phrase function should not be applied.

    How would I change the expression to achieve this? :confused:
     
    squishi, Aug 16, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well, it could probably be done via a regex, but you may consider preg_repace_callback, this allows you to write your own PHP function for the rewrite. In that function you could do your own checks. Again, there probably is a better way.
     
    premiumscripts, Aug 16, 2009 IP
  3. alons

    alons Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If every URL including your own URL goes to construct_phrase() function then in that functin just match your domain name and return the original data.
     
    alons, Aug 16, 2009 IP