简体   繁体   English

如何使用php将MySQL数据类型名称转换为正则表达式?

[英]How to convert MySQL datatype names into regular expressions using php?

Is there a php function to get regular expressions able to check if an input fits a certain MySQL data type? 是否有一个php函数来获取正则表达式,以检查输入是否适合特定的MySQL数据类型?

In example: 例如:

$foo = get_regex_for_data_type("int(10) unsigned");
echo $foo;

would return something like: 将返回类似:

/^[0-9]{1,10}$/

No, there is not a PHP function to do that. 不,没有PHP函数可以执行此操作。 You could write it yourself, but it would be very difficult to get it 100% right. 您可以自己编写它,但是很难100%正确地编写它。 For example, 0xFF is a perfectly valid value to insert into that field, but your regex would exclude it. 例如,0xFF是要插入该字段的完全有效的值,但是您的正则表达式将排除它。

Perhaps there is another way to accomplish what you're trying to do? 也许还有另一种方法可以完成您想做的事情? Is the problem that you're worried a value might be too large for the field? 您担心的问题是该值对于该字段可能太大吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM