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('<a href="http://%1$s" target="%2$s">%3$s</a>', $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
<form action="insert.php" method="post">
url: <input type="text" name="url" />
target: <input type="text" name="target" />
showingtext: <input type="text" name="showingtext" />

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');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.