Jump to content


New Members
  • Posts

  • Joined

  • Last visited

webtek's Achievements


Newbie (1/5)



  1. Thank you for the code, very helpful! It works perfectly using DOM. Your help is very appreciated
  2. Tried various different ways but it always end up failing, it either miss some tags or it creates a link inside another link I'm not even sure if i'm understanding it correctly, my code is a mess... $tags = array("test","testing"); $text = "I'm testing with this test zz ..."; foreach ( $tags as $tag ) { $array_text_only = preg_split('#<\w+[^>]*>|</\w+>#', $text); foreach ( $array_text_only as $text_only ) { $text_only_replace = preg_replace( '#\b('.$tag.'\pL*)#ui', "<a href=''>$1</a>", $text_only, 1 ); $text = str_replace($text_only,$text_only_replace,$text); } } What am I doing wrong?
  3. Nice, I got it to work using your solution, thanks! Is there a performance difference with this solution compared to using pure regex with lookarounds? I got thousands of tags to replace with links in a text, and the more tags in the text, the bigger the array from preg_split will get. Have to loop through the array for each of the thousands tags
  4. I use this code to replace words with links: $text = preg_replace( '#\b(test\pL*)#ui', "<a href='$tag_url'>$1</a>", $text, 1 ); But if I have a $text like this, it will try to create a link inside an existing <a href> tag, resulting in broken HTML code. $text = "hello this is a test with a <a href='https://google.com'>test link</a>"; How can I avoid this?
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.