Thanks for the code, I'm now using it but is there anyway to add st, nd, rd, th to the end, I know it will be complicated but it would be a great help as it currently doesn't make sense.
MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
You just need some if statements is all. Alot of if statements...
Actualy, it only requies three if-statements or cases. as you can see here http://www.php.net/strings where there are at least 4 usercomments with code to do exactly this. Like this one for stanance
PHP Code:
/*from lille dot findus at telia dot com
posted at [url]http://www.php.net/strings[/url] */
function nth($in)
{
if(strlen($in)>1 && substr($in,-2,1)==1)
return $in."th";
switch(substr($in,-1,1))
{
case 1:
return $in."st";
case 2:
return $in."nd";
case 3:
return $in."rd";
default:
return $in."th";
}
}
Heh, you can always count on you to know what to do.
Well, every time i'm looking at a page in the php-manual, i read the usercomments, which contain examplecode or comments on about everyfeature you'll ever need. Great timesaver
Actualy, it only requies three if-statements or cases. as you can see here http://www.php.net/strings where there are at least 4 usercomments with code to do exactly this. Like this one for stanance
PHP Code:
/*from lille dot findus at telia dot com
posted at [url]http://www.php.net/strings[/url] */
function nth($in)
{
if(strlen($in)>1 && substr($in,-2,1)==1)
return $in."th";
switch(substr($in,-1,1))
{
case 1:
return $in."st";
case 2:
return $in."nd";
case 3:
return $in."rd";
default:
return $in."th";
}
}
Thanks raf, I thought it would be possible somehow like that, however, how do I put it on the end of the original code?
You first include the code for the function somewhere above your actual code. Yhen instead of just printing the value, you apply the function to it. So if it's the oldcount that you wouls like to have postfixed, you'd have
PHP Code:
/*from lille dot findus at telia dot com
posted at [url]http://www.php.net/strings[/url] */
function nth($in)
{
if(strlen($in)>1 && substr($in,-2,1)==1)
return $in."th";
switch(substr($in,-1,1))
{
case 1:
return $in."st";
case 2:
return $in."nd";
case 3:
return $in."rd";
default:
return $in."th";
}
}
//here can go whatever code you want inbetween
$getcount = fopen("count.txt", "r");
while (!feof($getcount))
{
$oldcount .= fgets($getcount);
}
fclose($getcount);
$oldcount++;
$storenew = fopen("count.txt", "w");
fputs($storenew, $oldcount);
fclose($storenew);
print nth($oldcount);
Note, you only need to include the functionscode once, and then you can use it like a build in function (just using nth($variable)
You are the
Warning: fclose(): supplied argument is not a valid stream resource in /home/geoffers/public_html/f1unleashed/templates/counterfooter.php on line 26
440th visitor to this site
My code is
PHP Code:
You are the
<?PHP
function nth($in)
{
if(strlen($in)>1 && substr($in,-2,1)==1)
return $in."th";
switch(substr($in,-1,1))
{
case 1:
return $in."st";
case 2:
return $in."nd";
case 3:
return $in."rd";
default:
return $in."th";
}
}
$oldcount = file_get_contents("count.txt");
fclose($getcount);
$oldcount++;
$storenew = fopen("count.txt", "w");
fputs($storenew, $oldcount);
fclose($storenew);