【发布时间】:2018-07-06 16:22:17
【问题描述】:
我正在比较不同版本号的输入,如下所示:
testname-v01.03.001.01
testname-v02.01.001.03
...
我正在做一个比较,以确保没有任何输入被恶意输入到我的教科书中以损害我的 sql 表。
我正在做的是这样的:
<?php
function startsWith($needle, $haystack){
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}
$reqmethod = $_SERVER["REQUEST_METHOD"];
$textInput = "";
if( $reqmethod == "GET") {
$textInput = $_GET["my_input"];
}
$stringComparison = "v02.01.001.01";
if ( $textInput != ""){
$valid_input = startsWith("testname", $textInput); #See if text starts with version
#if not check if its a partial match
if (!$valid_input){
if(preg_match('/^[A-Z][0-9]+.[0-9].[0-9].[0-9]', $textInput)){
$textInput= "version-" + $textInput;
} else {
$textInputReadOut = "BAD VALUE";
$textInput= "";
}
}
?>
要让preg_match 与v01 相等,我是否可以这样做:[A-Z][0-9][0-9]?我已经尝试过了,但是该变量返回一个 BAD VALUE 而不是
【问题讨论】:
标签: php