[GLLUG] PHP Concatinating Strings

Ex Fed exfed at hotmail.com
Wed Feb 18 22:22:24 EST 2004

>I don't do PHP and am greatly surprised that PHP's mysql interface
>doesn't seem to have a printf-like command like every other scripting
>language I've seen. That lets you insert placeholders, pass in the
>values, and let the library do the quoting, like this:

PHP does in fact support PRINTF and SPRINTF

Here is an example of the use of printf:

$format = "The %s contains %d monkeys";
printf($format, $location, $num);

And an example of the use of sprintf
$isodate = sprintf("%04d-%02d-%02d", $year, $month, $day);

This sprintf formats strings you never know someday you might want to change 
the format of the date, so you can enter it into a mysql database.

You can pretty much format any type of string with it, and I believe you can 
escape slashes and other characters.

Lee D.

Store more e-mails with MSN Hotmail Extra Storage – 4 plans to choose from! 

More information about the linux-user mailing list