SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: sprintf?????

  1. #1
    SitePoint Zealot amrknt's Avatar
    Join Date
    Nov 2003
    Location
    india
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sprintf?????

    What's the actual uses of sprintf?
    I've seen somewhere something like this:
    PHP Code:
    $sql sprintf("SELECT COUNT(*) AS test FROM %s WHERE email = '%s' AND active = 'y'"$this->table_name$this->user_email); 
    Is it not good like this:
    PHP Code:
    $sql "SELECT COUNT(*) AS test FROM $this->table_name WHERE email = '$this->user_emails' AND active = 'y' "

  2. #2
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Have you read the documentation? http://ca3.php.net/sprintf

    I haven't had a use for it myself, but it looks lke it'd be handy for mathematical formatting, among others.
    Mike
    It's not who I am underneath, but what I do that defines me.

  3. #3
    SitePoint Zealot amrknt's Avatar
    Join Date
    Nov 2003
    Location
    india
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mike
    Have you read the documentation? http://ca3.php.net/sprintf

    I haven't had a use for it myself, but it looks lke it'd be handy for mathematical formatting, among others.
    Yes I'd, but I coudn't find any good example(not on the php.net, i'm
    talking about PHP scripts spread allover the web) to use this.

  4. #4
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sprintf() becomes handy when it comes eg to formatted output.
    if you want to print a list with several columns and don't wanīt to use tables you could do something like:
    PHP Code:
    sprintf("%4s %-11s %-40s %6s %6s""Qty""ItemNr.""Item""Price""Total");
    //-- ...
    while ( ... )
    {
        
    sprintf("%4s %-11s %-40s %6s %6.2f %s\n",
                 
    $qty$item_nr$name,
                 
    $price, ($p_sp_price $qty), $currency);

    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •