<p>.</p> <div class="hcb_wrap"> <pre class="prism undefined-numbers lang-php" data-lang="PHP"><code> function check_shortcode_new_remove($post_content) { $string_post_content = '[ultimate_popup]

[get name="logo"]

[get name="home" value="9999"]

[get name="home"]

';

$shortcode_allow_list = array( '[get name="logo"]', '[get name="header"]', '[get name="footer"]', '[ultimate_popup]', '

', '[thongbao]', '
', '', '[get name="game"]'

);

$product = "noproduct"; $run_product = true; if ($run_product != false) { $product = "product"; $shortcodes_including_list = all_shortcodes($post_content);

$shortcode_get = array(); foreach ($shortcodes_including_list as $key =&gt; $value_array) { $shortcode_get[] = $value_array[0]; }

$shortcode_get = array_values($shortcode_get); $string_post_content = $post_content; //[ultimate_popup] [get name="logo"] [get name="home"]

} else { # $shortcode_get = array('[ultimate_popup]', '[get name="logo"]', '[get name="home" value="9999"]', '

', '
'); }

// $array_delete = array_diff($shortcode_get, $shortcode_allow_list);

// $array_delete_new = array(); // foreach ($array_delete as $value) { // $trimmedValue = trim($value, '[]'); // $array_delete_new[] = $trimmedValue; // }

$first = array( '[get name="logo"]', '[ultimate_popup]', '

', '[thongbao]', '
' );

$two = array( '

', '
', '
', '[get name="header"]', '[get name="home"]', '', '[thongbao]', '[get name="game"]', '[get name="footer"]', '
', '
', '
', '[get name="thongkegame"]' ); $first = $shortcode_allow_list;

$first = array_map(function($item) { return str_replace(array('[', ']'), '', $item); }, $first);

$first = array_map(function($item) { return str_replace(' class=""', '', $item); }, $first);

// $two = $shortcode_get;

$one = array_map_remove_shortcode($shortcode_allow_list); // ok // $filtered = array_values(array_intersect($two, $first));

/*MẢNG SỐ 2*/ $string_new = create_array_from_content($string_post_content); $string_new_remove= (remove_if_have_and_add($string_new)); $two= array_map_remove_shortcode_skip_if_have($string_new_remove);

// print_r($one); // print_r($two); $array1 = $one; $array2 =$two;

// $arrayNew = array_filter($array2, function($value) use ($array1) { // return !in_array($value, $array1) &amp;&amp; !preg_match('/^\[.*\]$/', $value); // });

// $array1 = [ // 'get name="logo"', // 'ultimate_popup', // 'open', // 'thongbao', // 'close' // ];

// $array2 = [ // 'get name="header"', // 'get name="home"', // '[123445]', // 'preload', // 'thongbao', // 'get name="game"', // 'get name="footer"', // 'close', // 'close', // 'close', // 'get name="thongkegame"', // 'get name="logo"' // ];

/*LẤY GIÁ TRỊ CẦN XÓA*/ $arrayNew = array_filter($array2, function($value) use ($array1) { return !in_array($value, $array1) &amp;&amp; !preg_match('/^\[.*\]$/', $value); });

$array_remove = array_values($arrayNew);

/*XÓA GIÁ TRỊ KHỎI MẢNG 2*/ // $arrayNew = array_diff($two, $array_remove);

// $arrayNew= return_finsh_shortcode_content($arrayNew);

$array_remove= return_finsh_shortcode_content($array_remove);

// var_dump($string_new);

// var_dump($array_remove);

$result = array_diff($string_new, $array_remove); return $result; // $arrayNew = array_diff($array_remove, $string_new); // var_dump($result); // die;

/*TRẢ VÊ SHORTCODE*/

// foreach ($array_delete_new as $delete) { // $pattern = '/\[' . preg_quote($delete, '/') . '.*?\]\s*/'; // $string_new = preg_replace($pattern, '', $string_new); // }

// $string_return = $string_new;

// return $string_return; }

function create_array_from_content($string){

$array = explode("\n", $string); $array = array_map('trim', $array);

// Remove empty array elements $array = array_filter($array); // Add square brackets to each element in the array $array = array_map(function($item) { return $item ; }, $array); return $array; }

function remove_if_have_and_add($array){

foreach ($array as &amp;$value) { if (strpos($value, '[') === 0 &amp;&amp; strrpos($value, ']') === strlen($value) - 1) { $value = substr($value, 1, -1); } else { $value = '[' . $value . ']'; } } return $array;

}

function array_map_remove_shortcode($filtered){

$filtered = array_map(function($item) { return str_replace(array('[', ']'), '', $item); }, $filtered);

$filtered = array_map(function($item) { return str_replace(' class=""', '', $item); }, $filtered); $filtered = preg_grep('/class=("|\').*?("|\')/', $filtered, PREG_GREP_INVERT);

return $filtered; }

function return_finsh_shortcode_content($array1){

$arrayNew = [];

foreach ($array1 as $value) { if (strpos($value, '[') !== false) { // Nếu có dấu '[' $value = str_replace(['[', ']'], '', $value); // Xóa dấu '[]' } else { // Nếu không có dấu '[' $value = "[$value]"; // Thêm dấu '[]' } $arrayNew[] = $value; // Thêm giá trị vào mảng mới } return $arrayNew;

}

function array_map_remove_shortcode_skip_if_have($filtered) { $filtered = array_map(function($item) { // Skip values with square brackets if (strpos($item, '[') !== false || strpos($item, ']') !== false) { return $item; }

// Remove square brackets $item = str_replace(array('[', ']'), '', $item);

// Remove class="" $item = str_replace(' class=""', '', $item);

// Filter out values with class="value" if (preg_match('/class=("|\').*?("|\')/', $item)) { return ''; }

return $item; }, $filtered);

// Remove empty values $filtered = array_filter($filtered);

return $filtered; }</code></pre> </div> <p>.</p>