$title = '228-example-of-the-title'
我需要将字符串转换为:
标题示例
我该怎么做?
答案 0 :(得分:3)
单行,
$title = '228-example-of-the-title';
ucwords(implode(' ', array_slice(explode('-', $title), 1)));
explode(token, input)
),array_slice(array, offset)
)implode(glue, array)
),答案 1 :(得分:2)
$title = '228-example-of-the-title'
$start_pos = strpos($title, '-');
$friendly_title = str_replace('-', ' ', substr($title, $start_pos + 1));
答案 2 :(得分:1)
使用explode()拆分“ - ”并将字符串放入数组
$title_array = explode("-",$title);
$new_string = "";
for($i=1; $i<count($title_array); $i++)
{
$new_string .= $title_array[$i]." ";
}
echo $new_string;
答案 3 :(得分:1)
您可以使用以下代码
执行此操作$title = '228-example-of-the-title';
$parts = explode('-',$title);
array_shift($parts);
$title = implode(' ',$parts);
使用的函数:explode implode和array_shift
答案 4 :(得分:1)
$pieces = explode("-", $title);
$result = "";
for ($i = 1; $i < count(pieces); $i++) {
$result = $result . ucFirst($pieces[$i]);
}
答案 5 :(得分:1)
$toArray = explode("-",$title);
$cleanArray = array_shift($toArray);
$finalString = implode(' ' , $cleanArray);
// echo ucwords($finalStirng);