Answer the question
In order to leave comments, you need to log in
How to check the contents of an array in PHP?
There is an array $answer1[0], in it something like HTTP/1.1 302 FOUND.
I need to check if the array has HTTP/1.1 302 FOUND - perform an action.
if($answer1[0]=="HTTP/1.1 302 FOUND") doesn't work for unknown reasons, I'd like to know why.
print_r($answer1[0]) will print HTTP/1.1 302 FOUND.
I tried this:
strpos($answer1[0], "HTTP/1.1 302 FOUND")) - this option will display the position of the first match, that is, 0. 0 in if will not be executed) What is better to use in this case?
Answer the question
In order to leave comments, you need to log in
Try if (trim($answer1[0]) == "HTTP/1.1 302 FOUND")
. If you want with strpos, then
if (strpos($answer1[0], "HTTP/1.1 302 FOUND") !== false)
.
if($answer1[0]=="HTTP/1.1 302 FOUND")
doesn't work most likely because of trailing spaces, try this:
if(trim($answer1[0])=="HTTP/1.1 302 FOUND" )
with strpos:
if(strpos($answer1[0], "HTTP/1.1 302 FOUND")) !== false)
Ps:
here's one for you:
$answer1 = array_map('trim', $answer1); // this is if you have spaces on the sides
if(array_search("HTTP/1.1 302 FOUND", $answer1) !== false)
See also other string functions.
www.softtime.ru/bookphp/gl3_3.php
I'm sure you'll find a lot of interesting things there. Of course, the way is cooler - so preg_match with a regular expression, but if this is difficult to do yet, use string functions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question