Bricktop Posted August 3, 2009 Share Posted August 3, 2009 Hi all, I have an array of text and would like to check if the text in the array is present in a server response. So, this is how I would like it to work: $errors = array( "Once upon a time", "A long time ago", "In a galaxy far far away", "This script is broke" ); if (in_array(strpos($response, $errors))) But the above does not work, because you cannot use strpos on an array. If I do: $errors = array( "Once upon a time", "A long time ago", "In a galaxy far far away", "This script is broke" ); if (strpos($response, 'Once upon a time') || strpos($response, 'A long time ago) || strpos($response, 'In a galaxy far far away') || strpos($response, 'This script is broke)) Then it works fine, but obviously this is not an efficient way of achieveing the result. Anyone have any better ideas? Thanks Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 3, 2009 Share Posted August 3, 2009 Use a loop. Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 3, 2009 Share Posted August 3, 2009 use in_array //edit, wrong one <?php $errors = array( "Once upon a time", "A long time ago", "In a galaxy far far away", "This script is broke" ); $response = "Once upon a time"; if (in_array($response, $errors)) { echo "found"; } else { echo "not found"; } //script echos found ?> Quote Link to comment Share on other sites More sharing options...
FD_F Posted August 3, 2009 Share Posted August 3, 2009 foreach($errors as $check) { strpos($response, $check); } Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 3, 2009 Author Share Posted August 3, 2009 Thanks for the help guys - didn't think of using loops! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.