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

    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Simple(?) PHP/Regex question


    using preg_replace in php i'm trying to match a character and then make it bold for this example with <strong></strong> tags the character in question is ; however i only want to match it when its by itself and not part of a html character like &amp;amp; or &amp;lt;
    with that said i want ; to become <strong>;</strong> but &amp;amp; would remain untouched. I've tried a few regexp combinations but none have worked how i expect, they end up making &amp<strong>;</strong> which is not what i'm wanting

    edit: had to fix my &amp; to &amp;amp;s
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Solution Found


    well i managed to accidentally find a solution
    preg_replace("/(?<![&a-z])( ; )/is","<strong>$1</strong>",$string);
    I'm assuming this is doing a negated lookbehind for all characters a-zA-Z and the character & and then the second group is looking for the ; character
    This appears to be working when i look at the html source code of the final product after the string go thru the preg_replace.
    If anyone has a better solution I'm all ears

    edit: added spaces around the ; (darn smileys)

IMN logo majestic logo threadwatch logo seochat tools logo