在PHP字符串中搜索特定字符后的空白


Search a PHP string for whitespace after a particular character

这是我的字符串:

$string = '@ somebody and some other stuff';

如何检测@字符后面的空白?

如果我找到了匹配项,我想用原始字符串做点什么。

$string2 = '@ ';

如果我理解正确,你想找到@并删除空格吗?

$string = str_replace("@ ", "@", $string);

编辑你想要这个PHP源

<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);
// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}
?>
$string = preg_replace('/@ (.*)/', '@ ', $string);