Printf question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeanL
Forum Newbie
Posts: 2
Joined: Sat Sep 10, 2011 2:51 pm

Printf question

Post by jeanL »

I am using a Wordpress theme named The_erudite and I find a lot of PHP statments reading as follow: <?php printf( __( 'Posted in %s', 'erudite' ),get_the_category_list(', ') ) ?> <?php printf( __( 'By %s', 'erudite' ), erdt_get_author_posts_link() ) ?> <?php printf( __( 'Permalink to %s', 'erudite' ), the_title_attribute('echo=0') ) ?>" rel="bookmark"><?php the_title() ?>

Code: Select all

<?php the_excerpt(__( 'Read More <span class="meta-nav">&rarr;</span>', 'erudite' )) ?>[syntax=php]
What is the second parameter 'erudite' for ??? What does it do ??
I understand and use PHP quite a bit but don't understand this one !
Anybody an idea to explain this ?
Thanks for help
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Printf question

Post by flying_circus »

jeanL wrote:I am using a Wordpress theme named The_erudite and I find a lot of PHP statments reading as follow: <?php printf( __( 'Posted in %s', 'erudite' ),get_the_category_list(', ') ) ?> <?php printf( __( 'By %s', 'erudite' ), erdt_get_author_posts_link() ) ?> <?php printf( __( 'Permalink to %s', 'erudite' ), the_title_attribute('echo=0') ) ?>" rel="bookmark"><?php the_title() ?>

Code: Select all

<?php the_excerpt(__( 'Read More <span class="meta-nav">&rarr;</span>', 'erudite' )) ?>[syntax=php]
What is the second parameter 'erudite' for ??? What does it do ??
I understand and use PHP quite a bit but don't understand this one !
Anybody an idea to explain this ?
Thanks for help
When in doubt, RTFM :)
http://us3.php.net/manual/en/function.sprintf.php


Basically, printf/sprintf takes any number of arguments. The 1st parameter is a string containing variables (in the format of %<variable tyle>). After the first parameter is set with x number of variables, printf/sprintf expects that many more arguments.

Thus: printf( 'By %s', 'erudite' ) will output a string 'By erudite'.

%s is a variable, or place holder, for string type data.

If you want to use more than 1 variable, you can:
printf('You are %s posts on %s. The creator of this example is %s', 'viewing', 'devnetwork.net', 'flying_circus')
Output: You are viewing posts on devnetwork.net. The creator of this example is flying_circus'.
jeanL
Forum Newbie
Posts: 2
Joined: Sat Sep 10, 2011 2:51 pm

Re: Printf question

Post by jeanL »

Thank you very much ! I understand exactly how to use it, thanks to your examples.
Rgds from France
Jean
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Re: Printf question

Post by ok »

Well, you are not totally right.

Wordpress as a custom function named "__" (2 underscore chars). This function translate strings by using the PHP's gettext.

The Wordpress function "__" is defined in wp-includes/l10n.php, more on this function can be found here:
http://codex.wordpress.org/Function_Reference/_2

Basically, the first parameter is a string to be localized, and the second string is called the domain, which tells Wordpress from where to get the translation.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Printf question

Post by flying_circus »

ok wrote:Well, you are not totally right.

Wordpress as a custom function named "__" (2 underscore chars). This function translate strings by using the PHP's gettext.

The Wordpress function "__" is defined in wp-includes/l10n.php, more on this function can be found here:
http://codex.wordpress.org/Function_Reference/_2

Basically, the first parameter is a string to be localized, and the second string is called the domain, which tells Wordpress from where to get the translation.
Thanks for pointing that out, I am definately not a word press developer :)
Post Reply