Need to Search/Replace between link tags

Discussion in 'PHP' started by webuk44, May 25, 2007.

  1. #1
    I have an xml file that has various hyperlinks within <link>xxxx</link> tags.
    I want to be able to replace all the various links with my own.
    Is there a way I can search/replace every occurance of a <link> tag and replace with my own URL?
    I dont need this coded, a simple manual process will do.
     
    webuk44, May 25, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    
    $xml = preg_replace('/<link>[^<]+<\/link>/', '<link>http://example.com</link>', $xml);
    
    PHP:
     
    nico_swd, May 25, 2007 IP
  3. webuk44

    webuk44 Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have a file called sample.xml,
    how do I implement this code so it will give me a finished sample.xml?

    Thanks
     
    webuk44, May 25, 2007 IP