Php 修改现有脚本以接受其他参数
谢谢你抽出时间 我试图修改现有的PhP脚本,以接受第23行的用户输入字符串。现在它只接受数组中的数字Php 修改现有脚本以接受其他参数,php,Php,谢谢你抽出时间 我试图修改现有的PhP脚本,以接受第23行的用户输入字符串。现在它只接受数组中的数字 <?php function isJewishLeapYear($year) { if ($year % 19 == 0 || $year % 19 == 3 || $year % 19 == 6 || $year % 19 == 8 || $year % 19 == 11 || $year % 19 == 14 || $year % 19 == 17) return tru
<?php
function isJewishLeapYear($year) {
if ($year % 19 == 0 || $year % 19 == 3 || $year % 19 == 6 ||
$year % 19 == 8 || $year % 19 == 11 || $year % 19 == 14 ||
$year % 19 == 17)
return true;
else
return false;
}
function getJewishMonthName($jewishMonth, $jewishYear) {
$jewishMonthNamesLeap = array("Tishri", "Heshvan", "Kislev", "Tevet",
"Shevat", "Adar I", "Adar II", "Nisan",
"Iyar", "Sivan", "Tammuz", "Av", "Elul");
$jewishMonthNamesNonLeap = array("Tishri", "Heshvan", "Kislev", "Tevet",
"Shevat", "", "Adar", "Nisan",
"Iyar", "Sivan", "Tammuz", "Av", "Elul");
if (isJewishLeapYear($jewishYear))
return $jewishMonthNamesLeap[$jewishMonth-1];
else
return $jewishMonthNamesNonLeap[$jewishMonth-1];
}
$jdNumber = gregoriantojd(12, 12, 2016);
$jewishDate = jdtojewish($jdNumber);
list($jewishMonth, $jewishDay, $jewishYear) = explode('/', $jewishDate);
$jewishMonthName = getJewishMonthName($jewishMonth, $jewishYear);
echo "<p>The Jewish date of death is $jewishDay $jewishMonthName $jewishYear</p>\n";
?>
要接受而不是特定的数字,请用户输入。我想您可以使用$userinput,但这会导致预期的3个字符串的错误,得到一个
同样,这不是我的强项,但我作为一个项目的后端被投入其中。我并不期望为我编写代码,只是朝着正确的方向前进。谢谢。获取用户输入的方法很多,但我非常喜欢。如果设置了,则可以将日期及其输出作为输入解析为
gregoriantojd
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
</head>
<body>
<form>
<p>Date: <input type="text" name="datepicker" id="datepicker"></p>
<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>
<?php
function isJewishLeapYear($year) {
if ($year % 19 == 0 || $year % 19 == 3 || $year % 19 == 6 ||
$year % 19 == 8 || $year % 19 == 11 || $year % 19 == 14 ||
$year % 19 == 17)
return true;
else
return false;
}
function getJewishMonthName($jewishMonth, $jewishYear) {
$jewishMonthNamesLeap = array("Tishri", "Heshvan", "Kislev", "Tevet",
"Shevat", "Adar I", "Adar II", "Nisan",
"Iyar", "Sivan", "Tammuz", "Av", "Elul");
$jewishMonthNamesNonLeap = array("Tishri", "Heshvan", "Kislev", "Tevet",
"Shevat", "", "Adar", "Nisan",
"Iyar", "Sivan", "Tammuz", "Av", "Elul");
if (isJewishLeapYear($jewishYear))
return $jewishMonthNamesLeap[$jewishMonth-1];
else
return $jewishMonthNamesNonLeap[$jewishMonth-1];
}
if(
isset($_GET['datepicker']) &&
$datetime = DateTime::createFromFormat('m/d/Y', $_GET['datepicker'])
){
$jdNumber = gregoriantojd($datetime->format('m'), $datetime->format('d'), $datetime->format('Y'));
$jewishDate = jdtojewish($jdNumber);
list($jewishMonth, $jewishDay, $jewishYear) = explode('/', $jewishDate);
$jewishMonthName = getJewishMonthName($jewishMonth, $jewishYear);
echo "<p>The Jewish date of death is $jewishDay $jewishMonthName $jewishYear</p>\n";
}
jQuery UI日期选择器-默认功能
$(函数(){
$(“#日期选择器”).datepicker();
} );
日期:
有很多方法可以获得用户输入,但我真的很喜欢。如果设置了,则可以将日期及其输出作为输入解析为gregoriantojd
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
</head>
<body>
<form>
<p>Date: <input type="text" name="datepicker" id="datepicker"></p>
<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>
<?php
function isJewishLeapYear($year) {
if ($year % 19 == 0 || $year % 19 == 3 || $year % 19 == 6 ||
$year % 19 == 8 || $year % 19 == 11 || $year % 19 == 14 ||
$year % 19 == 17)
return true;
else
return false;
}
function getJewishMonthName($jewishMonth, $jewishYear) {
$jewishMonthNamesLeap = array("Tishri", "Heshvan", "Kislev", "Tevet",
"Shevat", "Adar I", "Adar II", "Nisan",
"Iyar", "Sivan", "Tammuz", "Av", "Elul");
$jewishMonthNamesNonLeap = array("Tishri", "Heshvan", "Kislev", "Tevet",
"Shevat", "", "Adar", "Nisan",
"Iyar", "Sivan", "Tammuz", "Av", "Elul");
if (isJewishLeapYear($jewishYear))
return $jewishMonthNamesLeap[$jewishMonth-1];
else
return $jewishMonthNamesNonLeap[$jewishMonth-1];
}
if(
isset($_GET['datepicker']) &&
$datetime = DateTime::createFromFormat('m/d/Y', $_GET['datepicker'])
){
$jdNumber = gregoriantojd($datetime->format('m'), $datetime->format('d'), $datetime->format('Y'));
$jewishDate = jdtojewish($jdNumber);
list($jewishMonth, $jewishDay, $jewishYear) = explode('/', $jewishDate);
$jewishMonthName = getJewishMonthName($jewishMonth, $jewishYear);
echo "<p>The Jewish date of death is $jewishDay $jewishMonthName $jewishYear</p>\n";
}
jQuery UI日期选择器-默认功能
$(函数(){
$(“#日期选择器”).datepicker();
} );
日期:
有两种方法。它们都要求您将$userinput变量转换为数组
如果:$userinput=“12 6 2016”代码>
你可以做:
$input = explode($userinput, ' ');
$jdNumber = gregoriantojd($input[0], $input[1], $input[2]);
另一种方法是将数组作为输入列表传递:
$jdNumber = call_user_func_array('gregoriantojd', $input);
未经测试,但应能正常工作。有两种方法。它们都要求您将$userinput变量转换为数组
如果:$userinput=“12 6 2016”代码>
你可以做:
$input = explode($userinput, ' ');
$jdNumber = gregoriantojd($input[0], $input[1], $input[2]);
另一种方法是将数组作为输入列表传递:
$jdNumber = call_user_func_array('gregoriantojd', $input);
未经测试,但应能正常工作