本文介绍了PHP-检测字符串之间的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测字符串中的空白?例如,我有一个名称字符串,例如:
How would I go about detecting whitespace within a string? For example, I have a name string like:
简·多伊"
请记住,我不想修剪或替换它,只需检测第一和第二个字符串之间是否存在空格.
Keep in mind that I don't want to trim or replace it, just detect if whitespace exists between the first and second string.
推荐答案
使用Josh建议的preg_match:
Use preg_match as suggested by Josh:
<?php
$foo = "Dave Smith";
$bar = "SamSpade";
$baz = "Dave\t\t\tSmith";
var_dump(preg_match('/\s/',$foo));
var_dump(preg_match('/\s/',$bar));
var_dump(preg_match('/\s/',$baz));
胜利:
int(1)
int(0)
int(1)
这篇关于PHP-检测字符串之间的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!