954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

using variables ins sprintf word strings

have problems understanding the logic of using variables inside this code. why ist it possible to use %s for different variables and how is it possible to use them as %1$s and %2$s...without even defining them somewhere...i just dont get it, the complete code can be viewed in the thread: hyperlink from url
could anybody help:


$hyperlink = sprintf('%3$s', $url, $target, $showingtext);

// Build the SQL query. This function will again replace each placeholder with the listed variable values respectively
$sql = sprintf("INSERT INTO `hyperlinktable2` SET `url` = '%s', `target` = '%s', `showingtext` = '%s', `hyperlink` = '%s'",
$url, $target, $showingtext, $hyperlink);

here is the form code to the variables

url:
target:
showingtext:

johng123
Light Poster
30 posts since May 2011
Reputation Points: 10
Solved Threads: 1
 
C#Jaap
Junior Poster in Training
50 posts since Sep 2009
Reputation Points: 15
Solved Threads: 10
 

See this example .
In you code you can change %1$s to %1 as all 3 string order is fixed.

echo $hyperlink = sprintf('<a href="http://%s" target="%s">%s</a>', 'url', 'target', 'showingtext');
vibhaJ
Posting Shark
931 posts since Apr 2010
Reputation Points: 161
Solved Threads: 183
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: