[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:

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

And an example of the use of sprintf
<?php
$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! 
http://click.atdmt.com/AVE/go/onm00200362ave/direct/01/



More information about the linux-user mailing list