SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    %s -> whats it??

    Hello,

    I am learning PHP and mySQL from Wrox's PHP Programming. I am stuck on a code and can't understand what does it means. Its basically a function and what it does is formats the text inside the function. Here is the code:

    PHP Code:
    function GenerateHTMLHeader($message
    {
    printf("font size=+4 face=Arial color="red"><B>");
    printf("%s</b></font><br>"$message);

    When we type GenerateHTMLHeader("Omair Haroon");
    it would display Omair Haroon in red color.

    The only thing I can't understand is what does %s in the fourth line stands for.

    Waiting for your help guys.


    -Omair
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  2. #2
    Shiver me timbers!! anthony_irl's Avatar
    Join Date
    Aug 1999
    Location
    Dublin, Ireland
    Posts
    495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Omair,

    I just bought this book myself but have yet to reach that stage of it yet.

    I'm nearly sure the %s stands for string and the second parameter passed to the printf function is the string you want it to print out. This is similiar to how C++ prints out strings and ints. I hope that helps.
    Anthony - How's tings?

    24 hours in a day, 24 beers in a case. Coincidence? I think not.
    Contact me by: PM Email NEW! Carrier Pigeon

  3. #3
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, Anthony is correct. The printf function in PHP is pretty much identical to that of C and C++.

    %s, %d, %f are a few examples of what's called 'format specifications' for an array of characters (strings), integer, and a floating point number respectively.

  4. #4
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So can I write $message instead of %s ?



    -Omair
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  5. #5
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that's correct.

    printf("$message</b></font><br>");

    would be a perfectly valid statement. It would perform the same thing as

    print("$message</b></font><br>");

    or

    echo "$message</b></font><br>";


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
  •