SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    Egypt
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I replace a line in a text file?

    Hello,
    I am trying to make a page that adds RSS feeds to an xml file, The way I was going to do it is, find the </channel> and replace it with the new feed with str_replace and put </channel> again but I found that it is not that simple because this way I am going to change it in the variable not the file. and also the pointer will be after </channel> not before it.

    So how can I replace the line </channel> with the feed I want to add?

  2. #2
    SitePoint Zealot DocDave's Avatar
    Join Date
    Sep 2004
    Location
    Milwaukee, WI, USA
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this.
    $newstring would be the content you wish to insert into the file.

    PHP Code:
    $xmlstring  implode("",file($xmlfile_path))
    $xmlstring  str_replace"</channel>"$newstring $xmlstring);
    $xmlfile fopen($xmlfile_path"w+");
    fwrite($xmlfile$xmlstring);
    fclose($xmlfile); 
    .:Blog:.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •