Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parsing a sitemap

    I am still relatively new to PHP, and I can't seem to come up with a code to parse a sitemap and find all the content between <loc>and</loc> tags. I tried using DOM using a snipit I found, but my server doesn't support it.

    any ideas for reading all the <loc>content here</loc> into an array?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Your server has DOM disabled? Why? Can you enable it? Or is this a shared host? Why would your hosting company have DOM disabled?

    You could use fsockopen() to get the contents of the page and then use regex to find the tag you're interested in... or perhaps even use simpleXMLelement to parse the page and find the tag using that object's methods. Not really sure that would work.

  • #3
    Regular Coder
    Join Date
    May 2011
    Posts
    239
    Thanks
    1
    Thanked 56 Times in 55 Posts
    You could use the following regular expression.

    PHP Code:
    $pattern '#<loc>[^<]+</loc>#si';
    if (
    preg_match_all($pattern$text$m))
    {
            
    $locs $m[0];



  •  

    Posting Permissions

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