I recently discovered the joys of using heredoc with sprintf and positions. Useful if you want some code to iterate, you can repeat placeholders.
<?php
function getNumber($num = 0) {
$foo = rand(1,20);
return ($foo + $num);
}
function getString() {
$foo = array("California","Oregon","Washington");
shuffle($foo);
return $foo[0];
}
function getDiv() {
$num = getNumber();
$div = sprintf( "<div>%s</div>", getNumber(rand(-5,5)) );
return $div;
}
$string = <<<THESTRING
I like the state of %1\$s <br />
I picked: %2\$d as a number, <br />
I also picked %2\$d as a number again <br />
%3\$s<br />
%3\$s<br />
%3\$s<br />
%3\$s<br />
%3\$s<br />
THESTRING;
$returnText = sprintf( $string, getString(),getNumber(),getDiv() );
echo $returnText;
?>
----
Server IP: 69.147.83.197
Probable Submitter: 198.67.17.9
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php
Edit -- https://master.php.net/note/edit/102709
Del: integrated -- https://master.php.net/note/delete/102709/integrated
Del: useless -- https://master.php.net/note/delete/102709/useless
Del: bad code -- https://master.php.net/note/delete/102709/bad+code
Del: spam -- https://master.php.net/note/delete/102709/spam
Del: non-english -- https://master.php.net/note/delete/102709/non-english
Del: in docs -- https://master.php.net/note/delete/102709/in+docs
Del: other reasons-- https://master.php.net/note/delete/102709
Reject -- https://master.php.net/note/reject/102709
Search -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.