在 PHP 字符串中搜索特定字符后的空格
Search a PHP string for whitespace after a particular character
这是我的字符串:
$string = '@ somebody and some other stuff';
如何检测 @ 字符后的空格?
如果我找到匹配项,我想用原始字符串做一些事情。
$string2 = '@ ';
如果我没理解错你想找到 @
并删除 space?
$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";
}
?>
$string = preg_replace('/@ (.*)/', '@ ', $string);
这是我的字符串:
$string = '@ somebody and some other stuff';
如何检测 @ 字符后的空格?
如果我找到匹配项,我想用原始字符串做一些事情。
$string2 = '@ ';
如果我没理解错你想找到 @
并删除 space?
$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";
}
?>
$string = preg_replace('/@ (.*)/', '@ ', $string);