function help php

Associate
Joined
19 Jul 2006
Posts
1,847
PHP:
// at the top of the page
function checknumber (){
$number=$_POST['number'];
$number= ereg_replace("[^0-9]","",$number);
$length= strlen($number);
$flag = true;
 if ($length==10)
{
 $flag= true;
 return $flag;
 }
 else {
 $flag=false;
 return $flag;
 }
  }
This logic works.

in main part of page i do
PHP:
<div id="mainblock">
<?php 
checknumber ();
if ($flag==true){
echo"	value is true do something";
 }
else{
echo" value is false	do something else";
}?>   
</div>
but it echo's valuse is false do something else even if the length does equal 10

what am i doing wrong now?

TIA
 
Thanks PaulM

functions look really good and useful and i dont think im using them to there full use.

I seam to write them and then not get the output i want and end up writing more lines of code rather than your simple
if (checknumber())
solution
 
Back
Top Bottom