这是我的字符串:
$string = '@ somebody and some other stuff';
如何检测@字符后面的空格?
如果我找到了匹配,我想用原始字符串做一些事情。
$string2 = '@ ';
答案 0 :(得分:2)
如果我理解正确,您想找到@
并删除空格?
$string = str_replace("@ ", "@", $string);
修改强> 你想要这个PHP source
<?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";
}
?>
答案 1 :(得分:0)
$string = preg_replace('/@ (.*)/', '@ ', $string);