plutomed Posted October 22, 2007 Share Posted October 22, 2007 I have an array with some bits in and it don't echo out properly. $footer = array( "names" => array("About Us", "Site Map", "Privacy Policy", "Contact Us"), "pages" => array(prefix()."index.php?pm=about_us", prefix()."index.php?pm=site_map", "javascript:win_open('".prefix()."includes/privacy_policy.php', 'Privacy_policy', 'directories=0, height=200, location=0, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=0, width=500');", prefix()."index.php?pm=contact_us") ); $count_footer = count($footer['names']); $i_footer = 0; while($i_footer < $count_footer) { $links_footer .= " <a href=\"".$footer['pages'][$i_footer]."\">".$footer['names'][$i_footer]."</a> |"; $i_footer++; } echo $links_footer; This is what it echo's: /new//new//new//new/ About Us | Site Map | Privacy Policy | Contact Us | The prefix is in the wrong place. How come? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 22, 2007 Share Posted October 22, 2007 Can you post the script for your "prefix" function? Ken Quote Link to comment Share on other sites More sharing options...
plutomed Posted October 22, 2007 Author Share Posted October 22, 2007 it just says echo "/new/"; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 22, 2007 Share Posted October 22, 2007 That is why. When you "echo" a string it goes directly to the browser screen, you need to return the string if you want to have it put into the string. Write it something like this: <?php function prefix() { return ('/new/'); } ?> BTW, I tightened up your code a little: <?php $footer = array("names" => array("About Us", "Site Map", "Privacy Policy", "Contact Us"), "pages" => array(prefix()."index.php?pm=about_us", prefix()."index.php?pm=site_map", "javascript:win_open('".prefix()."includes/privacy_policy.php', 'Privacy_policy', 'directories=0, height=200, location=0, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=0, width=500');", prefix()."index.php?pm=contact_us")); $count_footer = count($footer['names']); $i_footer = 0; $tmp = array(); for ($i_footer=0;$i_footer<count($footer['names']);$i_footer++) $tmp[] = ' <a href="' . $footer['pages'][$i_footer] . '">' . $footer['names'][$i_footer] . '</a>'; echo implode(' | ',$tmp); ?> Using an array to temporarily store the footer string and then using the implode function puts the " | " between the entries and you don't have a trailing " | ". Ken Quote Link to comment Share on other sites More sharing options...
plutomed Posted October 22, 2007 Author Share Posted October 22, 2007 Ah ok thanx. And thanx for the cleaning the code but use the other "|" at the end coz I cut the bit of code out that wasn't relevent. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.