php ereg function help?

  • mikewooten
  • Novice
  • Novice
  • mikewooten
  • Posts: 24

Post 3+ Months Ago

i'm using the datecheck () ereg function inside of a while loop and its giving me this error.
here's the function:




PHP Code: [ Select ]
 
function datecheck($intext) {  
 
   $result = ereg("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $intext, $trashed);  
 
   if ($result) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }  
 
   
 
 echo("\"$intext\" $isamatch<br>\n");    
 
   
 
}
 
 
  1.  
  2. function datecheck($intext) {  
  3.  
  4.    $result = ereg("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $intext, $trashed);  
  5.  
  6.    if ($result) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }  
  7.  
  8.    
  9.  
  10.  echo("\"$intext\" $isamatch<br>\n");    
  11.  
  12.    
  13.  
  14. }
  15.  
  16.  



here' s the error:

Fatal error: Cannot redeclare datecheck() (previously declared in /home/username/public_html/folder/thanks2.php:332) in /home/username/public_html/folder/thanks2.php on line 332


when i take the function outside of the loop, the form on the page just keeps copying itself all the way down the page, i'm guessing it has something to do with the loop, but i'm not sure whats going on with it, and why its giving me this error if
i don't have 2 functions with the same name? also i don't have an include file with the same function in that file.
can anyone tell me how i could fix this so that i don't get this error?

thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

What is happening is each time you run the loop you are redeclaring datacheck(); you'll need to move that function to right before your loop, or at the top of the page, or better yet a separate functions.php. Sorry I just like beeing uber-organized with my scripting :-P

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 145 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.