Is there an easier way to block things then ereg()?

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
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Is there an easier way to block things then ereg()?

Post by php_wiz_kid »

In my script I'm using ereg() to block certain number/symbols/letters when passed through an if statement so they don't get entered into a database. Now, I have super long lines of code using the ereg() function. Is there anyway I could put the unwanted numbers/symbols/letters in an external file and import them in so I don't have 150 ereg()'s in one if statement?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

You could add them into an array and then check each letter to see if its in the array using:

in_array();

?>
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

Would I have to do it with a loop? Could you please send an example. I'm looking at the PHP Manual, and I'm not seeing how I would do it. Thanks.
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

I figured out what you meant. That wouldn't work, I would have more lines of code now. The ereg() function would be easier. Thanks though.
Post Reply