views:

120

answers:

3

Hi All, 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

A: 

Everything seems to be in place to accept zero padded strings, have you checked the rest of the script?

Alix Axel
A: 

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"]))
0scar
Thank You for your nice input... i will do your suggestions for this topic... if you wish i have another link that maybe you inform there http://stackoverflow.com/questions/1960441/make-output-parallel-with-php-code-based/1963426#1963426
jones
Hi Oscar, also you typed i did all but nothing happens, tq
jones
+1  A: 

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'] );
}
poke
Thank You for your nice input... i will do your suggestions for this topic... if you wish i have another link that maybe you inform there http://stackoverflow.com/questions/1960441/make-output-parallel-with-php-code-based/1963426#1963426
jones
Hi Poke, Everything you typed i did, but change nothing bro.
jones
Hi Poke...how if i send you the complete script? because i am new to php, and just looking for some help, if you agree would you if i send the script through by email. Regards
jones
Just upload it to pastebin.com and add the link in your question
poke
Sorry that I didn't answer, however I suggest you to open a new question about that as I'm currently quite busy and can't look through the code that quickly. By opening a new question you invite others to help you as well.
poke
Oh... no Problem, just do your activity 1st and hopefully all be right, thx
jones