1

是否可以在 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();

}
4

3 回答 3

2

str_replace将返回一个字符串或一个数组,它不会改变原始变量,所以你应该这样做$object->link = str_replace('searched','replacement', $object->link);if $linkispublic

于 2013-02-18T16:04:22.223 回答
2

尝试这个:

$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();

}
于 2013-02-18T16:06:00.007 回答
0

尝试:

$object->link = str_replace('searched','replacement', $object->link);
于 2013-02-18T16:05:23.570 回答