<?php
function get_video() {
$stripper = "Content..., content...content...,
content...content...content..., no more...";
preg_match_all("/\/smi", $stripper, $search);
$unique = array_unique($search[0]);
$total = count($unique);
for($i=0; $i < $total; $i++)
{
$vid = $search[1][$i];
if ($vid > 0)
{
$random_numbers = rand(1, 1000);
$video_id = $vid."_".$random_numbers;
$stripper = str_replace($search[0][$i], $video_id, $stripper);
}
}
return $stripper;
}
echo get_video();
?>
I want to remove duplicate in $stripper, this is the result i need:
Content...1_195, content...content...2_963,
content...content...content..., no more...
I am using array_unique() function to remove the duplicate array. From my code above, if i print_r($unique), the duplicate array has been removed:
Array ( [0] => [1] => )
But if i echo get_video(), the duplicate still exist:
Content...1_195, content...content...2_963,
content...content...content...1_195(), no more...
I can’t figure out why!!! 🙁
Demo: http://eval.in/7178
To remove duplicates execute a
preg_replace_callbackand replace the duplicate one by “”. Use the following code just before yourpreg_match_allcall,See http://eval.in/7185