#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Posts
    75
    Rep Power
    6

    [Q] simple preg replace pattern


    In the following example if $link was contain '?', I lose my pattern
    any ideas ?
    [PHP
    $string = preg_replace('!<a[^>](.*)(href="'. $link .'")(.*)</a>!siU', $linkReplace, $string);
    [/PHP]

    2- what if i want to know more about these pattern ?

    thanks
  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2008
    Location
    North Carolina
    Posts
    2,674
    Rep Power
    2674
    1. preg_quote
    2. google regular expressions
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Posts
    75
    Rep Power
    6
    Thanks a lot,

    what if i don't want <a> tags which has a rel='nofollow' ?
    how can I put this exception ?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Posts
    75
    Rep Power
    6
    I can see that by adding ' ! '
    But i get errors
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    You're using " ! " as your delimiter, attempting to use it in the pattern is going to throw errors. ! has no special significance in regular expressions anyway.

    In order to find strings not containing other strings, you'd need to make use of lookaheads in your regular expression. At this point, a well-written tutorial or book will have a better chance of helping you than we will.

    Thread moved to regex.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo