Reputation: 2647
I have following string with repeated words like:
$string = 'This is titleThis is titleThis is Title';
Now I want to remove duplicate words This is titleThis is Title
as repeated for two times in my string.
I am looking for this output: This is title
.
I have tried with implode(',',array_unique(explode(',', $string)))
but not getting luck.
Upvotes: 0
Views: 1273
Reputation: 5231
Please use this one code. Explode the string on a space
instead of a ,
<?php
$string = 'This is titleThis is titleThis is Title';
echo implode(' ',array_unique(explode(' ', $string)));
Upvotes: 1