gpt4 book ai didi

php - 检查字符串中的空格

转载 作者:行者123 更新时间:2023-12-04 22:35:28 25 4
gpt4 key购买 nike

有没有办法检查空格?

例如,我不想想检查这样的空格...

$string = "The dog ran away!"; 并让它输出 Thedogranaway!

我想检查是否有条目是否为 ALL 空格和只有空格?...并让它输出错误!

基本上,我不希望能够输入所有空格,但仍然让它执行 mysql_query。
另外,有没有一种方法可以去掉字符串前的所有空格,而不是字符串的其余部分?

$string = ""WHITESPACE HERE"狗跑了!";

if(empty($string) OR $string == " "){ // crappy example of what i'm trying to do
echo "Try again, please enter a message!"; // error
} else {
mysql_query("UPDATE users SET mesg='$string'")or die(mysql_error()); // do something
echo $post;
}

最佳答案

还有 ctype_space(最简单的,imo,就是用来做这个的,没有做一堆不必要的字符串操作):

$str = "   \r\n   \t  ";
if (ctype_space($str)) {
echo 'All whitespace';
}
// All whitespace

关于php - 检查字符串中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1733174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com