TheJoey Posted September 3, 2009 Share Posted September 3, 2009 Is there a way to tell php collect information before a certain point? For example Go-go-go-stop-go-go-go after stop it wouldnt display anymore information, and is it possible to do this threw use of a $find. Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/ Share on other sites More sharing options...
tommyda Posted September 3, 2009 Share Posted September 3, 2009 doesnt make sense Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911351 Share on other sites More sharing options...
newbtophp Posted September 3, 2009 Share Posted September 3, 2009 preg_match Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911353 Share on other sites More sharing options...
lockdownd7 Posted September 3, 2009 Share Posted September 3, 2009 You may could use output buffering... Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911354 Share on other sites More sharing options...
Garethp Posted September 3, 2009 Share Posted September 3, 2009 preg_match('~^(.+)stop~', $input, $find); Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911366 Share on other sites More sharing options...
TheJoey Posted September 3, 2009 Author Share Posted September 3, 2009 output buffering? Sorry if i am unclear. What i mean is that i have a login script which is retreiving login information from a .txt but the other data in the txt seems to conflict and allways give me a "wrong password error" Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911428 Share on other sites More sharing options...
TheJoey Posted September 3, 2009 Author Share Posted September 3, 2009 preg_match('~^(.+)stop~', $input, $find); thanks gareth but could you explain what this is trying to do. Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911432 Share on other sites More sharing options...
Garethp Posted September 3, 2009 Share Posted September 3, 2009 Basically it takes $input, then it gets EVERYTHING from the beginning of the $input up until stop. It then stores that in the array $find. You may not believe it, but regex is one of the most powerful tools of PHP. You should look into these links http://au2.php.net/preg_match http://au2.php.net/preg_match_all http://au2.php.net/preg_replace http://www.regular-expressions.info/ Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911434 Share on other sites More sharing options...
TheJoey Posted September 3, 2009 Author Share Posted September 3, 2009 thank you when i tried impletmenting this into my code i got this. Warning: preg_match() expects parameter 2 to be string, array given in C:\xampplite\htdocs\Trial\New Folder\examplelogin1\php.php on line 7 line 7 being preg_match('~^(.+)||~', $lines, $find) $lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array $find = "$username:$password"; // form a string like you expect it to be in the array preg_match('~^(.+)||~', $lines, $find); Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911435 Share on other sites More sharing options...
Alex Posted September 3, 2009 Share Posted September 3, 2009 The source of the file must be in a string, not in an array, file() returns an array. Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911437 Share on other sites More sharing options...
TheJoey Posted September 3, 2009 Author Share Posted September 3, 2009 im using arrays to use the collected data, :o :o Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911440 Share on other sites More sharing options...
trq Posted September 3, 2009 Share Posted September 3, 2009 Why don't you post your code? Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911444 Share on other sites More sharing options...
TheJoey Posted September 3, 2009 Author Share Posted September 3, 2009 Yeh ofcourse sorry about not posting thought i did. <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; $lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array $find = "$username:$password"; // form a string like you expect it to be in the array preg_match('~^(.+)||~', $lines, $find); if(in_array($find,$lines)){ $_SESSION['logged_in'] = true; echo 'Logged in'; } else { echo 'You entered a wrong password'; } ?> Link to comment https://forums.phpfreaks.com/topic/172919-solved-quick-question/#findComment-911593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.