如何去除特殊字符?

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);

我得到了什么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}'

我在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'

我假设您想将代码从 PHP 移植到 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);

这是 PHP 解决方案:

<?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" 
// }