PDA

View Full Version : Country & State link labels


era
05-06-2006, 08:37 PM
Hi Folks,

I use phpLD Regional Directory, and in the regional display, it shows countries like "United_States_Of_America", which is fine for the link, but wrotten for link labels. I went and changed case, so now it displays united_states_of_america in the URL correctly, but now the link label looks the same.

I have been trying to take the new link label, and swap out the "_" with a " ", and change the first character to uppercase on big words. This I have accomplished with the following code -


{php}
function strtotitle($title) {
$title = ereg_replace("_", " ", $title);
$smallwordsarray = array( 'of','a','the','and','an','or','nor','but','is','i f','then','else','when', 'at','from','by','on','off','for','in','out','over ','to','into','with' );
$words = explode(' ', $title); foreach ($words as $key => $word) {
if ($key == 0 or !in_array($word, $smallwordsarray)) $words[$key] = ucwords($word);
}
$newtitle = implode(' ', $words); return $newtitle;
}

echo strtotitle("united_states_of_america");
{/php}

This works great, I'm down to a final gotcha; how do I embed the echo successfully in the main.tpl file?

I've tried {php}echo strtotitle("$listitem");{/php} but this displays the link blank. Any idea what part of the syntax I have wrong?

I'm still surprised that noone else who uses phpLD Regional Directory has made this a bigger deal. If you use it out of the box, the URL's look like -

/United States Of America

or your link labels look like united_states_of_america.

Can anyone provide constructive feedback on this?

Many thanks,

Eric