此转换需要preg_replace或最佳选项


Need a preg_replace or best option for this conversion

我相信这很简单,我已经尝试格式化了几个组合,例如S1,Ep1=10001或S1,Ep2=10002 preg_组合,但都失败了,而不是我的强项

我需要的格式如下:

$link = array('Episodes from link');
$str = preg_replace('/^s/+', '0', $link);
echo   $str(array(  
  '10001',
  '10002',
  '10003',
));

等等…

由于有空、逗号和字符,请继续使用多个零,如有任何帮助,我们将不胜感激。。。

感谢

你的问题很不清楚,我可能离得很远,但这是我对你问题的尝试。

$link = array('S1, Ep1', 'S1, Ep2', 'S1, Ep3', 'S1, Ep10');
$results = preg_replace_callback('~^S('d+)'D+('d+)$~m', 
         function($m) {
            $which = strlen($m[2]) > 1 ? '00' : '000';
            return $m[1] . $which . $m[2];
         }, array_values($link));
print_r($results);

输出

Array
(
    [0] => 10001
    [1] => 10002
    [2] => 10003
    [3] => 10010
)