句子的第一个词如何放在 span 中
How the first word of the sentence to put in the span
我使用 laravel 和 blade。我不知道 record.title 中的第一个单词是如何放入 span 中的。有谁知道并且可以帮助我吗?编辑:我忘记了最重要的事情。这是来自 cms october
的 htm 页面
<h2><span>The</span> {{ record.title }}</h2>
您可以将字符串拆分成单词:
$words = explode(' ',trim(record.title));
然后这样得到第一个:
$first_word = $words[0];
使用explode()
to create an array of words and str_after()
显示第一个词之后的所有词:
@php $sentence = explode(' ', $record->title) @endphp
<span>{{ $sentence[0] }}</span>
{{ $str_after($sentence, $sentence[0].' ') }}
October CMS 使用 twig 模板引擎。你可以在你的模板中做到这一点:
{{ record.title | split(' ')[0] }}
// for the rest of string
{{ record.title[1:] }}
我使用 laravel 和 blade。我不知道 record.title 中的第一个单词是如何放入 span 中的。有谁知道并且可以帮助我吗?编辑:我忘记了最重要的事情。这是来自 cms october
的 htm 页面<h2><span>The</span> {{ record.title }}</h2>
您可以将字符串拆分成单词:
$words = explode(' ',trim(record.title));
然后这样得到第一个:
$first_word = $words[0];
使用explode()
to create an array of words and str_after()
显示第一个词之后的所有词:
@php $sentence = explode(' ', $record->title) @endphp
<span>{{ $sentence[0] }}</span>
{{ $str_after($sentence, $sentence[0].' ') }}
October CMS 使用 twig 模板引擎。你可以在你的模板中做到这一点:
{{ record.title | split(' ')[0] }}
// for the rest of string
{{ record.title[1:] }}