<?php
function get_video() {
$stripper = "Content...[video=1], content...content...[video=2],
content...content...content...[video=1], no more...";
preg_match_all("/\[video=(.+?)\]/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();
?>
我想刪除重複的[視頻= 1] $脫衣舞,這是結果,我需要:正則表達式卸下串重複比賽
Content...1_195, content...content...2_963,
content...content...content..., no more...
我使用array_unique()函數刪除重複的數組。從上面我的代碼,如果我的print_r($唯一的),重複的陣列已被移除:
Array ([0] => [video=1] [1] => [video=2])
但是,如果我回聲get_video(),重複的[視頻= 1]仍然存在:
Content...1_195, content...content...2_963,
content...content...content...1_195([video=1]), no more...
我不明白爲什麼! :(
完美!謝謝! – richard