是否可以控制rand的输出,例如,如果我只是想让rand给我输出变量$ roll1的值,或者在rand运行或浏览器时六种可能性中的一半时间的值或数量是刷新,如何实现这一目标?
我的代码很糟糕,但我正在努力学习,我偶尔会得到一个,但它不一致,每次刷新页面我都想要1.
因此,如果我刷新页面6次,我应该从变量$ roll1中获得1次三次,而$ roll1的其余值应该是随机的.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>loaded dice</title>
</head>
<body>
<h1>loaded dice</h1>
<h3>loaded dice</h3>
<?php
// loaded dice, should roll the number 1 half the time out of a total of 6.
// So if I refreshed my browser six times I should at least see three 1's for roll1.
$roll1 = rand(1, 6);
// Okay is it possible to divide rand by two …Run Code Online (Sandbox Code Playgroud) 这是我的style.php脚本中的代码目标:用户应该能够选择并输入背景颜色和字体的不同选项.
这个带有css和php的代码片段叫做stlye.php,假设提供了我在outputform.php脚本上使用的变量.
<?php header("Content-type: text/css");
$gray = "#333";
$dkgreen = "#008400";
?>
body {
background:<?=$gray?>;
color:<?=$dkgreen?>;
}
Run Code Online (Sandbox Code Playgroud)
这是来自outputform.php的php脚本的一部分:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>
Your Output
</title>
<link rel="stylesheet" type="text/css"
media="screen" href="style.php">
Run Code Online (Sandbox Code Playgroud)
我很确定通过使用href ="style.php",我应该能够看到来自style.php的默认颜色:$ dkgreen用于字体颜色,$ grey用于在outputform.php上显示背景;但是,这个事实并非如此.
我做错了什么,或者我需要阅读什么来解决这个问题?
总体目标是将CSS变量输出到outputform.php,我可以在其中操作它们...给用户选择字体颜色和背景颜色.
现在是早上5点51分,谷歌的信息是压倒性的,并不想和我玩得很好,无论是我还是需要睡觉.
if ($tired == sleep)
{
print "get more coffee";
}
else
{
print "code badly...yeah, I am going to sleep now...................";
}
Run Code Online (Sandbox Code Playgroud) 这个函数numtoalpha如何打印出大于9的字母等价物?结果,如下所示:A为10,B为11,等等....
PHP.net甚至没有这个功能,或者我没有找到正确的位置,但我确信它说的功能.
<?php
$number = $_REQUEST["number"];
/*Create a condition that is true here to get us started*/
if ($number <=9)
{
echo $number;
}
elseif ($number >9 && $number <=35)
{
echo $number;
function numtoalpha($number)
{
echo $number;
}
echo"<br/>Print all the numbers from 10 to 35, with alphabetic equivalents:A for10,etc";
?>
Run Code Online (Sandbox Code Playgroud) 为什么数据_有下划线?
是否有更简单的方法来编写它,以便在代码可读性方面更有意义?
我的分析:
data_应该接受任何data_ is,通过postmessage表单中的变量请求消息并确保它的文本并连接所有这些:
$filename = 'data_'.$_REQUEST['postmessage'].'.txt';
Run Code Online (Sandbox Code Playgroud)
我是初学者,我对这段代码的分析可能是错误的,但我愿意从错误中吸取教训.
一位收件人:someone@example.com
mail("someone@example.com", "Subject: $subject",
$message, "From: $email" );
Run Code Online (Sandbox Code Playgroud)
如果我想要两个收件人,我可以这样做:
somone@example.com和tom@php.com
mail("someone@example.com", "tom@php.com", "Subject: $subject",
$message, "From: $email" );
Run Code Online (Sandbox Code Playgroud) 有可能将这个java代码片段转换为php吗?
public void testBalanceReturnsToZeroOnVending()
{
sodaVendor.insertCoin(50);
sodaVendor.insertCoin(20);
sodaVendor.insertCoin(5);
// The price is right!
assertEquals("We have entered correct money",
SODA_PRICE,
sodaVendor.getCurrentBalance());
sodaVendor.dispenseItem();
assertEquals("After vending, the balance of soda vending machine is zero",
0,
sodaVendor.getCurrentBalance());
}
Run Code Online (Sandbox Code Playgroud) 好的,我是正则表达式的noob,我正在使用这个网站作为我的正则表达式引物:
问题:使用s修饰符,下面的代码假设为echo 4,因为它找到了4个换行符.
但是,当我运行这个时,我得到一个(1),为什么?
<?php
/*** create a string with new line characters ***/
$string = 'sex'."\n".'at'."\n".'noon'."\n".'taxes'."\n";
/*** look for a match using s modifier ***/
echo preg_match("/sex.at.noon/s", $string, $matches);
/*The above code will echo 4 as it has found 4 newline characters.*/
?>
Run Code Online (Sandbox Code Playgroud) 是否有可能并且在php中的if语句中使用heredoc进行编码是否正确?
if($selection!='')
{
$price=getselection($selection,$getprice[$selection]);
if ($selection<8)
{
print 'Please enter the amount<br />';
print '<form action="" method="post"><input type="text" name="money1" value="'.$money1.'">';
print '<input type="text" name="money2" value="'.$money2.'">';
print '<input type="text" name="money3" value="'.$money3.'"><input type="submit">';
print '<input type="hidden" name="selection" value="'.$selection.'"';
print '</form><br>';
if (($money1!='')&&($money2!='')&&($money3!==''))
{
$total=$money1+$money2+$money3;
$money=getmoney($total);
$change=getchange($total,$price);
}
}
}
echo '</pre>';
Run Code Online (Sandbox Code Playgroud)
我试图避免摆脱PHP代码,跳进html然后再回到php,我只是试图保持PHP脚本上的一切; 另外,使用多个打印件是凌乱的,谢谢你没有火红.
我知道有更优雅的方法来设置一个html表单来接受男性或女性的输入; 但是,我正在学习,我只是想知道这是否也有可能:
//Incorporate two checks
if (empty($_POST['sex'])==FALSE && sanityCheck($_POST['sex'], 'string', 1)==TRUE)
{
// if the checks are ok for sex we assign sex to a variable
$sex = $_POST['sex'];
}
else
{
// if all is not well we echo an error message
echo 'Please enter a valid Gender';
// and exit the script
exit();
}
Run Code Online (Sandbox Code Playgroud)
如果是这样,我如何使用正则表达式进行检查?用户是否键入M或F.
我在想:
function checksex($sexcheck)
{
//Some regex here to check the sex?
return preg_match(' ', $sexcheck);
}
Run Code Online (Sandbox Code Playgroud)
然后调用checksex作为第三个检查添加到if条件,如下所示:
if (empty($_POST['sex'])==FALSE && sanityCheck($_POST['sex'], 'string', 1) …Run Code Online (Sandbox Code Playgroud) 鉴于:
x = MyFunc(2);
Run Code Online (Sandbox Code Playgroud)
我的理解:
变量x被赋值给函数MyFunc(2).
首先,调用MyFunc().返回时,其返回值(如果有)将分配给x.?