是否可以在 foreach 循环内的流中更改对象元素的子字符串?所以我尝试但它不起作用。
$xml= '';
foreach ($objetcs as $object){
str_replace('searched','replacement', $object->link);
//then I would call a function to render my rss
$xml .=$object->renderRSS();
}
str_replace
将返回一个字符串或一个数组,它不会改变原始变量,所以你应该这样做$object->link = str_replace('searched','replacement', $object->link);
if $link
ispublic
尝试这个:
$xml= '';
foreach ($objetcs as $object){
$object->link = str_replace('searched','replacement', $object->link);
//then I would call a function to render my rss
$xml .=$object->renderRSS();
}
尝试:
$object->link = str_replace('searched','replacement', $object->link);