1
$title = '228-example-of-the-title'

文字列を次のように変換する必要があります。

タイトルの例

どうすればいいですか?

4

6 に答える 6

3

ワンライナー、

$title = '228-example-of-the-title';
ucwords(implode(' ', array_slice(explode('-', $title), 1)));
  • これにより、文字列がダッシュ ( explode(token, input)) で分割されます。
  • 最初の要素を引いたもの ( array_slice(array, offset))
  • 結果のセットをスペース ( implode(glue, array)) で結合します。
  • 最後に、各単語を大文字にします (thanks salathe )。
于 2012-05-15T20:15:00.563 に答える
2
$title = '228-example-of-the-title'
$start_pos = strpos($title, '-');
$friendly_title = str_replace('-', ' ', substr($title, $start_pos + 1));
于 2012-05-15T20:11:29.940 に答える
1

explode()を使用して「-」を分割し、文字列を配列に配置します

$title_array = explode("-",$title);
$new_string = "";

for($i=1; $i<count($title_array); $i++)
{
$new_string .= $title_array[$i]." ";
}

echo $new_string;
于 2012-05-15T20:10:54.043 に答える
1

次のコードを使用してこれを行うことができます

$title = '228-example-of-the-title';

$parts = explode('-',$title);
array_shift($parts);
$title = implode(' ',$parts); 

使用される関数:爆発内 array_shiftを分解します。

于 2012-05-15T20:14:03.950 に答える
1
$pieces = explode("-", $title);
$result = "";
for ($i = 1; $i < count(pieces); $i++) {
    $result = $result . ucFirst($pieces[$i]);
}
于 2012-05-15T20:14:44.513 に答える
1
$toArray = explode("-",$title);
$cleanArray = array_shift($toArray);
$finalString = implode(' ' , $cleanArray);
// echo ucwords($finalStirng);
于 2012-05-15T20:18:57.073 に答える