#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Location
    Adelaide - Australia
    Posts
    77
    Rep Power
    3

    Sitemap.php - Ampersand and cache


    Hi People,

    I've created a sitemap.php and following the recommendations of "sitemap protocol" I added this class to the urls.

    Code:
    // This is the protocol required for the XML in sitemap.php
    function cleanMAP($string)
    {
    	$string = str_replace("&","&",$string);
    	$string = str_replace("'","'",$string);
    	$string = str_replace('"','"',$string);
    	$string = str_replace(">",">",$string);
    	$string = str_replace("<","&lt;",$string);
    
    	return $string;
    }
    And applied it as such:
    Code:
    echo '<loc>'.cleanMAP($url).'</loc>'. PHP_EOL;
    However, if I cut a url from the sitemap.xml such as:

    Code:
    http://127.0.0.1/demo/index.php?action=blog_entry&amp;entryid=8
    And post it in a browser,

    I get this?
    Code:
    Warning: fopen(cache/): failed to open stream: No such file or directory in C:\xampp\htdocs\demo\includes\functions.php on line 138
    Warning: fputs() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\demo\includes\functions.php on line 139
    Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\demo\includes\functions.php on line 140
    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\demo\templates\black_star\blog_entry.php on line 49
    I've looked at "other" sitemap's and they don't convert & to &amp; but that's besides the point?

    So my question is:

    Do the spiders reiterate the url as & - Or are they going to run into a brick wall of errors - because it all works fine if I alter the url &amp; to &?

    And the other thing is - I can't possibly see how to "clean" the url request to access the cached information.

    And if it will make it easier - I'll post the sitemap.php here if requested.

    Thanks.
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    Encoding the & as &amp;s is about making the content (the URL) safe for where you're putting it (the XML). When anybody reads the XML content as XML they'll get the decoded version back; you simply copied what you saw in the file and that's not the same thing.

    You should fix those warnings in your code. They hint at larger problems that may leave your site unsafe.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Location
    Adelaide - Australia
    Posts
    77
    Rep Power
    3
    Thanks requinix,

    And for pointing out yet another error which seems to have multiplied since upgrading to php5*

IMN logo majestic logo threadwatch logo seochat tools logo