liamthebof Posted August 3, 2008 Share Posted August 3, 2008 OK, the tital is a lie, I just cant get it to work. SO far: $animal = $_POST["animal"]; ^From a form input box, works perfect. if ($animallist = fopen("currentanimals.cfg", 'r')) { $list = stream_get_contents($animallist, -1, 0); if(preg_match("|$animal|",$list) === TRUE) { echo "Already present"; } else { echo "Will be added"; } members.cfg Cat Dog Fish Money OK, I would like it so when someone enters Dog in my form, this bit of php searches my animal list and checks if what it searched for was there. If so, say 'Already present', else say, 'To be added'. However, when I enter Dog, it says 'To be added'. Why? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/117896-solved-preg_match-not-working/ Share on other sites More sharing options...
JasonLewis Posted August 3, 2008 Share Posted August 3, 2008 What is the output of $list? Link to comment https://forums.phpfreaks.com/topic/117896-solved-preg_match-not-working/#findComment-606461 Share on other sites More sharing options...
genericnumber1 Posted August 3, 2008 Share Posted August 3, 2008 There are much simpler and more efficient ways to do it... <?php $list = file_get_contents('currentanimals.cfg'); // Easier on the eyes than your current implementation if(stripos($list, $animal) === false) // stripos is faster than preg_match, and is case insensitive... if you want case sensitivity use strpos() { echo 'Will be added'; } else { echo 'Already present'; } sorry I kind of dodged your question Link to comment https://forums.phpfreaks.com/topic/117896-solved-preg_match-not-working/#findComment-606464 Share on other sites More sharing options...
liamthebof Posted August 3, 2008 Author Share Posted August 3, 2008 Worked perfectly, thank you so much, Link to comment https://forums.phpfreaks.com/topic/117896-solved-preg_match-not-working/#findComment-606467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.