How to remove special characters?
foreach ($login_and_logout_list['rval'] as $k => $v) {
$login_time[] = $v['login_time'];
$logout_time[] = $v['logout_time'];
$create_time[] = $v['create_time'];
$i++;
}
var_dump($login_time);
What i am getting in var_dump
array (size=3)
0 => string '{09:46},{09:48}'
1 => string '{05:04},{07:04},{08:40},{08:54}'
2 => string '{05:20}'
What i want in var_dump is
array (size=3)
0 => string '09:46 | 09:48'
1 => string '05:04 | 07:04 | 08:40 | 08:54'
2 => string '05:20'
I assume you want to port your code from PHP to JavaScript.
var a = ['{09:46},{09:48}', '{05:04},{07:04},{08:40},{08:54}', '{05:20}']
a = a.map(o => {
return o.replace(/(}\,{)/mg, ' | ').replace(/(}|{)/mg, '');
})
console.log(a);
Here's the PHP solution:
<?php
$a = ['{09:46},{09:48}', '{05:04},{07:04},{08:40},{08:54}', '{05:20}'];
$a = array_map( function($o){
$o = preg_replace('/(}\,{)/m', ' | ', $o);
$o = preg_replace('/(}|{)/m', '', $o);
return $o;
}, $a);
var_dump($a);
// output
// array(3) {
// [0]=> string(13) "09:46 | 09:48"
// [1]=> string(29) "05:04 | 07:04 | 08:40 | 08:54"
// [2]=> string(5) "05:20"
// }