Shopping Cart Forum

Go Back   eShop Forums - eCommerce Help Forum for Shopping Cart Owners. > Tech Corner > PHP/HTML/CSS/JavaScript and Servers
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
PHP/HTML/CSS/JavaScript and Servers Pick up tips and exchange info on the technical side of having a web presence.

click here for ink cartridges for all types of printer
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 30-10-2007, 05:01 AM
Lawrence Lawrence is offline
Forum Admin
 
Join Date: Aug 2007
Location: Kenley, Surrey, UK
Posts: 1,226
Thanks: 2
Thanked 82 Times in 82 Posts
Default How to Print Correct Plurals using PHP

One thing that niggles me on some sites is the incorrect use of plurals. I'm sure you've all seen examples of this, such as "You have 1 items in your basket" or "1 guests online". It's just pure laziness on behalf of the programmer and can easily be rectified with a single line of code.

This is how it's done


PHP Code:
echo "You have $number " . ($number == 'Item' 'Items') . " in your basket."
Where $number is the number of items in the user's basket. That's all there is to it.

There are some slightly more complicated versions than that, such as "There is 1 guest online" and "There are 17 guests online", but I'm sure you can work out how to do this by using the same principle I used above.
__________________
Lawrence
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
php


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Google

Edible Graphics, Affordable E-Commerce, Web Shops & Custom Form Scripts
Click here for domain name registration and web hosting
tech news, product reviews, the latest home and business technology, the latest in digital imaging


Content Relevant URLs by vBSEO 3.0.0