php - The str_ireplace and preg_replace attemt? -
I am trying to replace a string with one original text. ( Print Preg_replace attempts: > P> Print I just have one I want to put the rule here so that What to add is the exception of special characters if zinc is near one of them (i.e.: I want to be an executable, the letter is Thanks! You can define such exceptions with negative In your case you want zinc -> gt; zn ) Example: 'zinc zinc zinc zinc 3! Zinc Zodiac # Zinc Zinc 9 Zinc @ zinc @ want to: 'zn zn zn zinc3! Zn zincmatic #zinc zinc9 zn @zinc @ stack_replayed attempts: zn zinc zn zinc3! Zinc zinc # zinc zinc 9 zn @ zinc @ .
$ text = 'zinc zinc Zinc zinc 3! Zinc zodiac # zinc zinc 9 zinc '; $ Word = 'zinc'; $ Attr = 'zn'; $ Result = preg_replace ("/ \ b ($ word) \ b / i", $ attr, $ text); $ Return result; zn zn zn zinc3! Zn zincmatic #zn zinc9 zn @zn @ Almost what I want: It seems that in zinc, zn even if some special character near ! Zinc is or # zonx but if any number is zinc9 or junkmic like text # zinc is passed to # zink , @ zinc @ to @zink_ and ! Zinc to ! Zn changes into #zinc , zinc@ , @ zanx ) # , and , @ \ b Behave like and can actually be used in conjunction. (? & Lt;! [# & Amp; @]) to check the previous character, and (?! [ # & Amp; @]) Click .
= preg_replace ("/ (? & Lt;?! [# & Amp; @]!) \ B ($ word) \ b ([# & amp; @]) / I ", $ Attr, $ text);
Comments
Post a Comment