So I have PHP code that looks like this:
$message = 'Here is the result: %s';
I just used% s as an example. This is basically a placeholder for whatever. Then I pass the string to the function, and I want this function to replace% s with a value.
What do I need to do for this? Do I need to do some regular expression and use preg_replace () or something else? or is there an easier way to do this?
sprintf, . < > .
$output = sprintf("Here is the result: %s for this date %s", $result, $date);
%s, , , printf . , :
%s
$text = sprintf($message, "replacement text");
, ...
$find = array( '#name#', '#date#' ); $search = array( 'someone\ name', date("m-d-Y") ); $text_result = str_replace($find, $search, $text);
, $text /html $text_result
sprintf, C printf sprintf.
sprintf
printf
:
$placeholder = 's'; str_replace("%".$placeholder,$$placeholder,$message);
% s $s,