2012-10-18 39 views
0

我想做一個數組上的字符串替換。PHP的str_replace不工作在我的情況下

我..

str_replace('texts', 'testssssss', $test->html); 

$test->html回報

,我想,以取代所有文本到testssssss ..

key 1 

<div> 
    <a href='texts.company.name.html'>test</a> 
</div> 



Key 2 

<div> 
    other html... 
</div> 


Key 3 

<div> 
    other html... 
</div> 

Key 4 

<div> 
    <a href='texts.department.name.html'>department</a> 
</div> 

more... 

感謝您的幫助!

+2

你記得返回字符串將'str_replace'的輸出分配給一個變量? –

+0

你真的重新分配了返回值嗎? –

+0

您必須將str_replace的結果分配給某個變量或其他變量 –

回答

5

你需要的地方分配新值,str_replace函數不會自動覆蓋的主題:

$test->html = str_replace('texts', 'testssssss', $test->html); 
0

的功能,所以你需要啓動它變量$ = str_replace函數

相關問題