You are here: Re: Problems with str_replace « PHP Programming Language « IT news, forums, messages
Re: Problems with str_replace

Posted by kurt.milligan on 04/16/06 14:22

Hello

Unless I'm missing something, I think the problem is that you are not
capturing the output of str_replace(). It does not modify the string
in-place; it returns the modified version of the string. So, instead
of:

str_replace('</rss>', '', $xmlFileContents);
str_replace('</channel>', '', $xmlFileContents);

do:

$xmlFileContents = str_replace('</rss>', '', $xmlFileContents);
$xmlFileContents = str_replace('</channel>', '', $xmlFileContents);

HTH

-Kurt

marcomputers@gmail.com wrote:
> Hi,
>
> I'm trying to automatically update an existing rss podcast file using
> php and the str_replace function.
> Every time I add a media file, it should read the .rss file into a
> string, take the closing </channel> and </rss> tags out of it, and add
> the new rss file info to the end of the existing string, writing it
> back to the rss file. However, str_replace will not replace the
> </channel> and </rss> tags with ' '. I'm new to php, any help would be
> appreciated.
>
> Start Code:
> ----------------
> $xmlFile = "/home2/kingshar/public_html/podcast_test.rss";
> $xmlReadHandle = fopen($xmlFile, 'r') or die("Cannot open podcast
> file");
> $xmlFileContents = fread($xmlReadHandle, filesize($xmlFile));
> fclose($xmlFile);
>
>
> //Search and delete closing rss tag
> str_replace('</rss>', '', $xmlFileContents);
> //Search and delete closing channel tag
> str_replace('</channel>', '', $xmlFileContents);
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация