Jump to content

erase duplicate words?


jmace

Recommended Posts

I was wonder how I can use preg_replace() to change a string like this:

Sponge Face Painting Applicators Medium Sponge Applicator

Into a string like this:

Face Painting Medium Sponge Applicator

In other words, because the word "Sponge" is in the string twice, and "Applicator" is in the string twice (except that the first ends in an s) they would be gone. I've tried stuff like:

$title = preg_replace('/(?:\W|^)(\w*?)(?:\W.*?)(?=\1)/',"",$title);

But it's way off and gives me:

Sponge Applicator

 

Any help would be great!

Link to comment
https://forums.phpfreaks.com/topic/219240-erase-duplicate-words/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.