所以我在google上找到了这个SHORTHAND PHP方法:
if(isset($a))
{
$a = TRUE;
}
else
{
$a = FALSE;
}
Run Code Online (Sandbox Code Playgroud)
可以在单行语句中转换为:
$a = isset($a) ? TRUE : FALSE;
哪个工作正常,我有一个脚本,我无法应用SHORT HAND方法.
PHP:
<?php
$letters = ['1' => 'A', '2' => 'B', '3' => 'C'];
$data['LETTER'] = "";
foreach($letters as $id => $letter)
{
$data['LETTER'] .= "<option value=$id>".$letter."</option>";
}
$html = file_get_contents('test.html');
echo $html = str_replace(array_keys($data),array_values($data),$html);
?>
Run Code Online (Sandbox Code Playgroud)
我已经完全使用了这个SHORTHAND METHOD,它根本不起作用
$data['LETTER'] = foreach($letters as $id => $letter) ? "<option value=$id>".$letter."</option>" : "";
是否有可能缩短上面的脚本?
我有一个验证生日的正则表达式:
if(!preg_match('/^(0?[1-9]|1[012])[- .\/](0?[1-9]|[12][0-9]|3[01])[- .\/](19|20)?[0-9]{2}$/', $_POST['bday'])
{
echo 'enter your birthdate in a valid format. mm/dd/yyy';
}
Run Code Online (Sandbox Code Playgroud)
这是:
正确的月份
闰年日期不准确
2月30日和31日接受
并且20年接受大于2013年
我几个月只做了正确的,我怎样才能做更准确的生日验证?还是有其他方法来验证生日?
我想要的输出是:
验证2月份的闰年日期
年份不得超过2010年
OUTPUT:
02/14/2010
我对正则表达式有点帮助吗?
我试图将旧网站转换为使用mysqli而不是mysql.
用这段代码命中了一个小块
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue) : mysqli_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break; …Run Code Online (Sandbox Code Playgroud)