WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP Utilities - correct grammar helpers: the plural, to be and to have
Categories : PHP, Utilities, Beginner Guides Click here to Update Your Picture
Fabien HADDADI
Date : Nov 09th 2010
Grade : 3 of 5 (graded 1 times)
Viewed : 7736
File : 5065.php
Images : No Images for this code example.
Search : More code by Fabien HADDADI
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

In the '2 cents functions that bring a lot to your website' family, you can add in a general include, let's call it a library of utilities that you call from absolutely every PHP page of your website, a set of functions which purpose is to help spelling correctly when building dynamically a report.

e.g. No more "1 results have been found for your search",
but "1 result has been found for your search", or "17 results were found for your search"

The functions found in the attached file are to be included in a "utils.inc" or whatever file you put all of your helpers in, and included as a:

require_once "utils.inc";

into your files.
Remember to place utils.inc in a folder that is visible to your include_path PHP Configuration variable.

You could then use them in situations like:

$sql = sprintf("SELECT COUNT() FROM book WHERE abstract LIKE ' %s%%' OR abstract LIKE '%s %%'", $search_text, $search_text);

$result = mysql_query($sql);

$hits = mysql_num_rows($result);

printf("<div>%d result%s %s found for your search <em>%s</em></div>'",
$hits, plural_s($hits), plural_was($hits), $search_text);

// and so forth...

<?php

// ...
// excerpt from utils.inc
// ...

// everyone will like this one:
function plural_s($n) {
        return
abs($n) > 1 ? 's' : '';
}


//English localised website designers will like these ones:

/*****************************************************************************/
function plural_has($n) {
        return
abs($n) > 1 ? 'have' : 'has';
}

/*****************************************************************************/
function plural_is($n) {
        return
$n > 1 ? 'are' : 'is';
}

/*****************************************************************************/
function plural_was($n) {
        return
$n > 1 ? 'were' : 'was';
}



// Whereas the French counterparts will appreciate those:

/*****************************************************************************/
function pluriel_a($n) {
        return
$n > 1 ? 'ont' : 'a';
}

/*****************************************************************************/
function pluriel_la($n) {
        return
$n > 1 ? 'les' : 'la';
}

/*****************************************************************************/
function pluriel_le($n) {
        return
$n > 1 ? 'les' : 'le';
}

/*****************************************************************************/
function pluriel_tent($n) {
        return
$n > 1 ? 'ent' : 't';
}

/*****************************************************************************/
function pluriel_ntent($n) {
        return
$n > 1 ? 'nnent' : 'nt';
}

/*****************************************************************************/
function pluriel_autre($n, $genre = 'm') {
        return (
$genre == 'm'? ($n > 1 ? "d'autres" : "un autre") : ($n > 1 ? "d'autres" : "une autre"));
}
?>



News management class
Categories : PHP, PHP Classes, Beginner Guides
PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem
Simple POST and GET example
Categories : PHP, Beginner Guides, Form Processing, HTML and PHP
Newbie Notes #4 - Trapping dumb MySQL query errors
Categories : PHP, Databases, MySQL, Debugging, Beginner Guides
PHP Event Logger
Categories : PHP, Log Files, Errors and Logging, Beginner Guides
Get the self URL of current page
Categories : PHP, URLs, Beginner Guides
Add, Edit /Update & Delete all in one Contact Management Form
Categories : PHP, MySQL, Databases, Beginner Guides
Using PHP to show text in random colors
Categories : PHP, Beginner Guides, Strings
Ensure that a specific value lies within a specific range.
Categories : PHP, Beginner Guides, Data Validation
Human readable PHP password generator
Categories : PHP, Security, Beginner Guides, Arrays
Newbie Notes #3 - What went wrong? A useful little debugging aid
Categories : PHP, Beginner Guides, Debugging
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
How to Create a Shoutbox Using PHP & MySQL
Categories : PHP, MySQL, Web Applications, Beginner Guides, HTML and PHP
Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides