php读取从零号开始的情况

发布于 2024-08-16 02:12:30 字数 1575 浏览 4 评论 0原文

愿你能帮助我... 很多年前,我的朋友给了我下面介绍的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧时光的容颜 2024-08-23 02:12:30

您应该使用 php 内部函数,例如 is_numericempty。并避免使用带有空字符串的字符串连接(无论出于何种原因),而只需确保这些常量(我猜它们是常量)兼容并且一切都很好。

if ( isset( $teks['chapter'] ) && !is_numeric( $teks['chapter' ) )
{
    if ( !empty( $teks['chapter'] ) )
        echo Chapter_need_number;
    unset( $teks['chapter'] );
}

if ( isset( $teks['verse'] ) && !is_numeric( $teks['verse'] ) )
{
    $temp_array = explode( '_', teks['verse'], 2 );
    if ( count( $temp_array ) >= 2 && is_numeric( $temp_array[0] ) && is_numeric( $temp_array[1] ) )
    {
        $teks['verse'] = intval( $temp_array[0] );
        $teks['verse_end'] = intval( $temp_array[1] );
        if ( teks['verse_end'] <= teks['verse'] )
        {
            echo Verse_range_need_larger_ending;
            unset( $teks['verse'] );
            unset( $teks['verse_end'] );
        }
    }
    else
    {
        if ( !empty( $teks['verse'] ) )
            echo Verse_need_number;
        unset( $teks['verse'] );
    }
}
if ( isset( $teks['verse'] ) && !isset( $teks['chapter'] ) )
{
    echo Verse_need_chapter;
    unset( $teks['verse'] );
}

You should make use of php internal functions like is_numeric and empty. 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.

if ( isset( $teks['chapter'] ) && !is_numeric( $teks['chapter' ) )
{
    if ( !empty( $teks['chapter'] ) )
        echo Chapter_need_number;
    unset( $teks['chapter'] );
}

if ( isset( $teks['verse'] ) && !is_numeric( $teks['verse'] ) )
{
    $temp_array = explode( '_', teks['verse'], 2 );
    if ( count( $temp_array ) >= 2 && is_numeric( $temp_array[0] ) && is_numeric( $temp_array[1] ) )
    {
        $teks['verse'] = intval( $temp_array[0] );
        $teks['verse_end'] = intval( $temp_array[1] );
        if ( teks['verse_end'] <= teks['verse'] )
        {
            echo Verse_range_need_larger_ending;
            unset( $teks['verse'] );
            unset( $teks['verse_end'] );
        }
    }
    else
    {
        if ( !empty( $teks['verse'] ) )
            echo Verse_need_number;
        unset( $teks['verse'] );
    }
}
if ( isset( $teks['verse'] ) && !isset( $teks['chapter'] ) )
{
    echo Verse_need_chapter;
    unset( $teks['verse'] );
}
小情绪 2024-08-23 02:12:30

我要在这里大胆猜测,因为我不太明白这个问题,但我认为你应该改变这个

if($teks["verse_end"] <= $teks["verse"])

if(intval($teks["verse_end"]) <= intval($teks["verse"]))

I'm gonna take a wild guess here, becuase I didn't quite get the question, but I think you should change this:

if($teks["verse_end"] <= $teks["verse"])

to this

if(intval($teks["verse_end"]) <= intval($teks["verse"]))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文