添加“产生绯闻;在没有"-"的第6个字符之后在字符串的末尾


add "-" after every 6th charater without "-" at the end of the string

我有一个24长的字符串$string = "b46844869365d5c9138834b8",我想在每6个字符之后添加"-",所以我有b46844-869365-d5c913-8834b8

我尝试了以下解决方案:

$string = implode("-", str_split($string,6));
$string = wordwrap($string, 6, '-', true);
$string = chunk_split($string, 6, '-');

但是它们都在结果的末尾添加了一个"-"所以我得到:

b46844-869365-d5c913-8834b8-

有什么建议吗?

试试:

<?php
$string = "b46844869365d5c9138834b8";
$s = str_split($string,6);
echo implode("-",$s);
?>

试试这个,它最后没有添加-

echo wordwrap('b46844869365d5c9138834b8' , 6 , '-' , true );
输出:

b46844-869365-d5c913-8834b8
相关文章: