// Может быть разное значение
$value = 'Parametr 1|Parametr 2|Parametr 3';
$explode = explode('|', $value);
// Может быть разное значение
$template = '<em>[param:0]</em>';
$out = preg_replace_callback(
'/\[param:(\d+)\]/i',
function($data) use($explode){
return $explode[(int)$data[1]];
},
$template
);
echo $out;
лучше полностью разделять клиентскую часть от серверной и использовать полный RESTfull API
$template = '{username}, здравствуйте. у вас {count} сообщений, от {nickname}';
$variables = [
'{username}' => 'Николай',
'{count}' => 10,
'{nickname}' => 'LYMIX'
];
$content = str_replace(array_keys($variables), array_values($variables), $template);
var list = {
"FailedCount": [{
"FailedCount_MEAS_VALUE": 1,
"DATETIME_CURRENT": "12:01"
}, {
"FailedCount_MEAS_VALUE": 0,
"DATETIME_CURRENT": "12:02"
}, {
"FailedCount_MEAS_VALUE": 3,
"DATETIME_CURRENT": "12:03"
}, {
"FailedCount_MEAS_VALUE": 4,
"DATETIME_CURRENT": "12:04"
}],
"SucceededCount": [{
"SucceededCount_MEAS_VALUE": 110
}, {
"SucceededCount_MEAS_VALUE": 120
}, {
"SucceededCount_MEAS_VALUE": 130
}, {
"SucceededCount_MEAS_VALUE": 140
}]
};
list.AllCount = [];
for (var i = 0; i < list.FailedCount.length; i++){
list.AllCount[i] = {};
list.AllCount[i].AllCount_MEAS_VALUE = parseInt(list.FailedCount[i].FailedCount_MEAS_VALUE) + parseInt(list.SucceededCount[i].SucceededCount_MEAS_VALUE);
}
console.log(list);
function get_submenu($parent)
{
db_connect();
$result = mysql_query("SELECT * FROM menu WHERE parent='$parent' ORDER BY id");
$res_array = [];
while($row = mysql_fetch_assoc($result))
{
$res_array[] = $row;
}
return $res_array;
}
var cookieValue = $.cookie("test");
if(!cookieValue) {
// your code
$.cookie("test", 1);
}
def main(args):
r = list(get_search_results('Hilary Duff'))
with open('output.json', 'wb') as o:
json.dump(r, o, sort_keys = True, indent = 4)