php读取从零号开始的情况
愿你能帮助我... 很多年前,我的朋友给了我下面介绍的 php 脚本代码,现在我想更改它可以从零开始读取编号,
现有的可能读取 1:1、10:200 等。但我也想从 01 开始读取: 01、0000002:0120 等...
function is_valid_number($sesuatu)
{
if(preg_match("/^([0-9]+)$/", $sesuatu)) return(TRUE);
else return(FALSE);
}
//--------------
if(isset($teks["chapter"]) && (is_valid_number($teks["chapter"]) === FALSE))
{
if(strcmp($teks["chapter"], "") != 0) echo "".Chapter_need_number.""; //bhs
unset($teks["chapter"]); //Just get rid of it.
}
if(isset($teks["verse"]) && (is_valid_number($teks["verse"]) === FALSE))
{
//There is a non-numerical character in verse. We /should/ be able to examine it for range.
$temp_array = explode("-", $teks["verse"], 2);
if(isset($temp_array[0]) && isset($temp_array[1]) && is_valid_number($temp_array[0]) === TRUE && is_valid_number($temp_array[1]) === TRUE)
{
$teks["verse"] = $temp_array[0];
$teks["verse_end"] = $temp_array[1];
// echo ("<h3>".Verse_range." \"" . $temp_array[0] . "\" - \"" . $temp_array[1] . "\"</h3>\n"); //bhs
if($teks["verse_end"] <= $teks["verse"])
{
echo "".Verse_range_need_larger_ending."";//bhs
unset($teks["verse"]);
unset($teks["verse_end"]);
}
}
else
{
if(strcmp($teks["verse"], "") != 0) echo "".Verse_need_number.""; //bhs
unset($teks["verse"]); //Just get rid of it.
}
}
if(isset($teks["verse"]) && !isset($teks["chapter"]))
{
echo "".Verse_need_chapter.""; //bhs
unset($teks["verse"]); //Just get rid of it.
}
//--------------
谢谢
May you can help me...
many years ago my friend gave me php script code presented below, now i want to change it can read numbering start from zero
existing just possible read 1:1, 10:200 etc.. but i want to make also possible read from 01:01, 0000002:0120 etc...
function is_valid_number($sesuatu)
{
if(preg_match("/^([0-9]+)$/", $sesuatu)) return(TRUE);
else return(FALSE);
}
//--------------
if(isset($teks["chapter"]) && (is_valid_number($teks["chapter"]) === FALSE))
{
if(strcmp($teks["chapter"], "") != 0) echo "".Chapter_need_number.""; //bhs
unset($teks["chapter"]); //Just get rid of it.
}
if(isset($teks["verse"]) && (is_valid_number($teks["verse"]) === FALSE))
{
//There is a non-numerical character in verse. We /should/ be able to examine it for range.
$temp_array = explode("-", $teks["verse"], 2);
if(isset($temp_array[0]) && isset($temp_array[1]) && is_valid_number($temp_array[0]) === TRUE && is_valid_number($temp_array[1]) === TRUE)
{
$teks["verse"] = $temp_array[0];
$teks["verse_end"] = $temp_array[1];
// echo ("<h3>".Verse_range." \"" . $temp_array[0] . "\" - \"" . $temp_array[1] . "\"</h3>\n"); //bhs
if($teks["verse_end"] <= $teks["verse"])
{
echo "".Verse_range_need_larger_ending."";//bhs
unset($teks["verse"]);
unset($teks["verse_end"]);
}
}
else
{
if(strcmp($teks["verse"], "") != 0) echo "".Verse_need_number.""; //bhs
unset($teks["verse"]); //Just get rid of it.
}
}
if(isset($teks["verse"]) && !isset($teks["chapter"]))
{
echo "".Verse_need_chapter.""; //bhs
unset($teks["verse"]); //Just get rid of it.
}
//--------------
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 php 内部函数,例如
is_numeric
和empty
。并避免使用带有空字符串的字符串连接(无论出于何种原因),而只需确保这些常量(我猜它们是常量)兼容并且一切都很好。You should make use of php internal functions like
is_numeric
andempty
. And refrain from using string concatenation with empty strings (for whatever reason), instead just make sure those constants (I guess they are constants) are compatible and everything is fine.我要在这里大胆猜测,因为我不太明白这个问题,但我认为你应该改变这个
:
I'm gonna take a wild guess here, becuase I didn't quite get the question, but I think you should change this:
to this