2017-04-20 50 views
-3

空間例如HTML標記堅強,如果我有以下格式的數組我想忽略包含在PHP

<div><strong>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</strong></div> 

<div><strong>Ravjaja</strong></div> 

<div><strong>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</strong></div> 

<div><strong>yuaiiaiia</strong></div> 

<div></div> 

我想從空間忽略,這意味着我的數組應該成爲像這樣除去

<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div> 

<div><strong>Ravjaja</strong></div> 

<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div> 

<div><strong>yuaiiaiia</strong></div> 

<div></div> 

<div></div> 

後是否有任何可能的方式我認爲拆分並使用在PHP 陣列函數代替我以這種方式試圖

$ keywords = preg_split(「<div>」,$ lval); print_r($ keywords); 和思想來提取每個標籤並刪除強勁,但我無法以這種方式做

+0

你嘗試過什麼?請閱讀[如何提問](https://stackoverflow.com/help/how-to-ask)。 – k0pernikus

+0

對不起,我是新來的StackOverflow感謝提示 – yerzu

回答

0
$elements = array(
    '<div><strong>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</strong></div>', 
    '<div><strong>Ravjaja</strong></div>', 
    '<div><strong>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</strong></div>', 
    '<div><strong>yuaiiaiia</strong></div>', 
    '<div></div>' 
); 

foreach ($elements as $key => $element) { 
    if (strpos('&nbsp', $element) !== FALSE) { 
     $elements[$key] = str_replace('<strong>', '', $element); 
     $elements[$key] = str_replace('</strong>', '', $element); 
    } 
} 
+0

謝謝你的解決方案,但我仍然需要細化,如果什麼陣列(「

        
」, ‘
Ravjaja
’, ‘
         
’, ‘
yuaiiaiia
’, 「
」)我給了已經是一個數組中的值 有沒有一種方法,爲 – yerzu

+0

分裂它由

+0

didnt get that can u please elaborate – yerzu

0

唯一可行的方法應該是這樣的

$my_array=str_replace("<div><strong>&nbsp;","<div>",$my_array); 
    $my_array=str_replace("&nbsp;</strong>","",$my_array);