recursion - Stored values and echoed values different in php recursive function -
recursion - Stored values and echoed values different in php recursive function -
hey guys making head hurt.
i writing recursive function go through directory of files create xml sitemap.
i have come across problem in if echo out value shows want, if store (to write file @ end) value different.
function dirtoarrayxml($dir, $langcode, $data) { $result = array(); $cdir = scandir($dir); $str = ""; foreach ($cdir $key => $value) { if (!in_array($value,array(".",".."))) { if (is_dir($dir . "/" . $value)) { $result[$value] = dirtoarrayxml($dir . "/" . $value, $langcode, $data); } else { $result[] = $value; if(endswith($value, ".php")) { $page = substr($value, 0, -4); $str .= " <url> <loc>http://www.example.com/".$dir."/".$page."</loc> <changefreq>monthly</changefreq>"; echo " http://www.example.com/".$dir. "/".$page; $languages2 = array("en","de","el","es","ru","tr"); foreach($languages2 $lang2) { $jazz = substr($dir, 3); $filepath = $_server['document_root']."/".$lang2."/".$jazz."/".$page .".php"; if($langcode != $lang2) { if(file_exists($filepath)) { echo " http://www.formacompany.com/".$lang2."/".$jazz."/".$page; $str.=" <xhtml:link rel=\"alternate\" hreflang=\"".$lang2."\" href=\"http://www.example.com/".$lang2."/".$jazz."/".$page ."\"/>"; } } } $str.=" </url>"; $data.=$str; } } } } homecoming $data; }
the outputted value in file
<url> <loc>http://www.example.com/ru/company-details</loc> <changefreq>monthly</changefreq> <xhtml:link rel="alternate" hreflang="en" href="http://www.example.com/en//company-details"/> <xhtml:link rel="alternate" hreflang="de" href="http://www.example.com/de//company-details"/> <xhtml:link rel="alternate" hreflang="es" href="http://www.example.com/es//company-details"/> </url>
whereas echoed values are
http://www.example.com/ru/folder/company-details http://www.example.com/en/folder/company-details http://www.example.com/de/folder/company-details http://www.example.com/ed/folder/company-details
why values different? how can stored values match echoed?
in code have this:
$str .= " <url> <loc>http://www.example.com/".$dir."/".$page."</loc> <changefreq>monthly</changefreq>"; echo "http://www.example.com/".$dir. "/".$page;
in several places, set different thing $str
variable, while echo
out different string.
find instances of $str.=
sets markup , convert includes string want, ie:
$str .= "http://www.example.com/".$dir. "/".$page;
php recursion echo
Comments
Post a Comment