sprintf-met-array
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* same as sprintf() except here you insert an array
*
* @author Iltar van der Berg
* @version 1.1.0
*
* @param string $input
* @param array $array
* @return string
*/
function sprintf_array($input, $array)
{
if(is_array($input))
{
die('<strong>sprintf_array:</strong> $input cannot be an array');
}
if(!is_array($array))
{
die('<strong>sprintf_array:</strong> $array must be an array');
}
if(count($array) == 0)
{
die('<strong>sprintf_array:</strong> $array must contain atleast 1 item');
}
$output = "\$output = sprintf('" . $input . "', '" . implode("', '", $array) . "');";
eval($output);
return $output;
}
// voorbeeld
$string = 'something like %s, is wrong. %s';
$array = array('this', 'right?');
$view = sprintf_array($string, $array);
echo $view;
?>
/**
* same as sprintf() except here you insert an array
*
* @author Iltar van der Berg
* @version 1.1.0
*
* @param string $input
* @param array $array
* @return string
*/
function sprintf_array($input, $array)
{
if(is_array($input))
{
die('<strong>sprintf_array:</strong> $input cannot be an array');
}
if(!is_array($array))
{
die('<strong>sprintf_array:</strong> $array must be an array');
}
if(count($array) == 0)
{
die('<strong>sprintf_array:</strong> $array must contain atleast 1 item');
}
$output = "\$output = sprintf('" . $input . "', '" . implode("', '", $array) . "');";
eval($output);
return $output;
}
// voorbeeld
$string = 'something like %s, is wrong. %s';
$array = array('this', 'right?');
$view = sprintf_array($string, $array);
echo $view;
?>