Regex to match words or phrases in string but NOT match if part of a URL or inside tags. (php)

后端 未结 7 1135
终归单人心
终归单人心 2020-12-06 23:20

I am aware that regex is not ideal for use with HTML strings and I have looked at the PHP Simple HTML DOM Parser but still believe this is the way to go. All the HTML tags w

7条回答
  •  有刺的猬
    2020-12-06 23:40

    Improvisation. It should link only if it is a whole word "Amazon" and not words like AmazonWorld.

    $result = preg_replace('%\bAmazon(?![^<]*)\b%i', 'Amazon', $subject);
    

提交回复
热议问题