【发布时间】:2016-02-22 01:50:07
【问题描述】:
我有一个这样的字符串:
$content = 'Hi @steve, have you seen what @dave wrote?';
我基本上只想找到直接跟在 @ 符号后面的单词(如 twitter 提及),然后循环遍历每个结果,与它们一起执行任务。
我知道如何从整个字符串中去掉 @ 字符:
$strip_at = str_replace( '@', '', $content );
这将导致 $strip_at 成为:
Hi steve, have you seen what dave wrote?
但是我将如何使用 str_replace 来定位每个“提及”,删除仅留下单词(在本例中为名称)的 @ 符号,然后将每个“提及”的结果存储在一个数组中到一个新变量中?
想要的结果:
$mentions = array('steve','dave');
然后我可以遍历 $mentions 并对结果进行处理,例如:
foreach ($mentions as $mention) {
echo 'This persons name is '.$mention.'<br />';
}
【问题讨论】:
标签: php arrays variables str-replace