Hello
Here is the problem:
I have this example string:
$string = "Product 1, Product 2, Product 3, Product 4, Product 5, Product 6, Product 7, Product 8, Product 9, Product 10, Product 11, Product 12, Product 13";
Now i wan't to check if string has multiple same names (or numbers) and to be cleaned using array_unique function.
First, those products will be stripped to "tags" with this function:
function split_tags($string) {
$array = preg_split("/[\s]*[, ][\s]*/", $string);
while(list($key,$val)=each($array)){
if($val<>" " and strlen($val) > 0){
$tag .= "$val, ";
}
}
$tag=substr($tag,0,(strLen($tag)-2));
return $tag;
}
So the $string will looks like this:
Then this function should do the "magic":
function unique_tags($array) {
$array = implode(',',array_unique(explode(',', $array)));
return $array;
Here is desired output:
But my script give's this output:
So it almost works.
I also tryed to change $string to this (see: , before Product 1):
[code]$string = ", Product 1, Product 2, Product 3, Product 4, Product 5, Product 6, Product 7, Product 8, Product 9, Product 10, Product 11, Product 12, Product 13";
[/code]
But it don't do anything.