您好,欢迎访问一九零五行业门户网

PHP中如何控制一个方法的字符串类型参数长度小于等于255字节?

注意是字节哦
回复内容: 注意是字节哦
//直接报错function test($str) { if (!is_string($str) or strlen($str) > 255) { throw new exception('not a string or too long'); }}//自动截断function test2($str) { if (!is_string($str)) { throw new exception('not a string'); } $str = substr($str, 0, 255); //php的substr是二进制安全的}
其它类似信息

推荐信息