Page 1 of 1

Global Variable

Posted: Fri Aug 08, 2008 10:08 am
by guerillacity
Hello ALL, I am trying to check a string using a function and get out the result of the function.

I can display the result in the function but i need to display it outside the function:

Code: Select all

<?    $WORD='!"£$%^&*()dsf)(*&^%$£"_+@:';
             
         
         function CheckWord($ZeWord)
              {   
                                  
              $ZeWord=trim($ZeWord); 
              $ZeWord=strtoupper($ZeWord);            
              $ZeWord=str_replace(" ","",$ZeWord);  
              
              
              
                for($i=32; $i<=47; $i=$i+1)
                {       
                    $ZeWord=str_replace(chr($i),"",$ZeWord);
                }
                
                
                for($i=58; $i<=64; $i=$i+1)
                {
                    $ZeWord=str_replace(chr($i),"",$ZeWord);
                }
                
                
                for($i=91; $i<=96; $i=$i+1)
                {                   
                    $ZeWord=str_replace(chr($i),"",$ZeWord);
                }
                
                
                for($i=123; $i<=255; $i=$i+1)
                {                   
                    $ZeWord=str_replace(chr($i),"",$ZeWord);
                }
                            
             
              echo "<br>ZeWord = $ZeWord <br>";//DISPLAYS
            
              }
                          
              
                
         CheckWord($WORD);       
             
         echo "<br>ZeWord = $ZeWord <br>";
           ?>

Re: Global Variable

Posted: Fri Aug 08, 2008 10:28 am
by filippo.toso
You can use http://www.php.net/return or pass the parameter as reference using the &

Re: Global Variable

Posted: Fri Aug 08, 2008 10:46 am
by guerillacity
filippo.toso wrote:You can use http://www.php.net/return or pass the parameter as reference using the &
CHEERS im new to PHP nd tat worked perfectly thanks, i used Return.

like:

Code: Select all

 
     <?    $WORD='!"£$%^&*()dsf)(*&^%$£"_+@:';
                 
             
             function CheckWord($ZeWord)
                  {  
                                     
                  $ZeWord=trim($ZeWord);
                  $ZeWord=strtoupper($ZeWord);            
                  $ZeWord=str_replace(" ","",$ZeWord);  
               
                   for($i=58; $i<=64; $i=$i+1)
                   {
                       $ZeWord=str_replace(chr($i),"",$ZeWord);
                   }
              
                
                 return $ZeWord;
              
                 }
                          
                  
            $newWord=CheckWord($WORD);      
                
            echo "<br>newWord = $newWord <br>";
              ?>