Global Variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
guerillacity
Forum Newbie
Posts: 7
Joined: Wed Aug 06, 2008 3:04 pm

Global Variable

Post 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>";
           ?>
filippo.toso
Forum Commoner
Posts: 30
Joined: Thu Aug 07, 2008 7:18 am
Location: Italy
Contact:

Re: Global Variable

Post by filippo.toso »

You can use http://www.php.net/return or pass the parameter as reference using the &
guerillacity
Forum Newbie
Posts: 7
Joined: Wed Aug 06, 2008 3:04 pm

Re: Global Variable

Post 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>";
              ?> 
 
Post Reply