SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: %s -> whats it??
-
Oct 26, 2001, 07:45 #1
- 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);
}
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.
-Omair36Host.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...."
-
Oct 26, 2001, 07:56 #2
- 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.
-
Oct 26, 2001, 08:18 #3
- 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.
-
Oct 26, 2001, 08:19 #4
- 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 ?
-Omair36Host.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...."
-
Oct 26, 2001, 08:47 #5
- 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