Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm checking some html for a string and the result I'm getting is not as expected
$html = "<body>Link</body>";
if(strpos($html, "href=\"http://domain.com") === FALSE)
echo "Not Found";
else
echo "Found";
It always return "Found" even though it's not actually found (I don't want it found) in this example?
Should I be using a different function?
string http://domain32a.com isn't same as http://domain.com. You also have some syntax errors, try:
$html = "<body>Link</body>";
if(strpos($html, "href=\"http://domain32a.com") === FALSE)
echo "Not Found";
else
echo "Found";
Change Your code to this
<?php
$html = "<body><a href='http://domain32a.com'>Link</a></body>";
if(strpos($html, "href=\"http://domain.com") === FALSE){
echo "Not Found";
} else {
echo "Found";
}
?>
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I want to compare two arrays with each other with this code:
if($jobids !== null){
if (isset($_COOKIE["djsearchquery"])){
$cookiequery[] = unserialize($_COOKIE['djsearchquery']);
$arrayequal = ($cookiequery == $jobids);
$consolelog = $cookiequery;
$consolelog[] = $jobids;
$consolelog[] = $arrayequal;
if($arrayequal == false){
$response = array(
'jobids' => $jobids,
'markerpositions' => $markerpositions,
'consolelog' => $consolelog
);
setcookie('djsearchquery', serialize($jobids), time()+3600);
echo json_encode($response);
}
}
In the console the arrays are pictured exactly the same:
Can someone explain to me why $arrayequal returns false? I donĀ“t understand it.
try to change
$cookiequery[] = unserialize($_COOKIE['djsearchquery']);
to
$cookiequery = unserialize($_COOKIE['djsearchquery']);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I tried to echo out the $rinse variable, I get nothing
But I do get one for the $rang['email'], any clues would be good
I also tried doing $rinse == $rang['email'];
while($rang = mysql_fetch_assoc($results))
{
if ($rang['email'] = $rinse){
echo $rang['email'];
}
$rinse = $rang['email'];
}
my code updated:
echo $rinse;
if ($rang['email'] == $rinse){
echo $rang['email'];
}
$rinse = $rang['email']
This is still not working for me
You need two = in your if statement.
if ($rang['email'] == $rinse){
You should add double ==. This is comparion, a single = means set to
while($rang = mysql_fetch_assoc($results))
{
if ($rang['email'] == $rinse){
echo $rang['email'];
}
$rinse = $rang['email'];
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm having trouble making a empty string to have something inside, I'm also removing some other unnecessary characters from that string which works.
$desc = strip_tags($mapAnnotationArray);
$mapAnnotationArrayOutput = str_replace( array('"', '(' , ')'), '', $desc);
$mapAnnotationArrayOutput = trim($mapAnnotationArrayOutput);
if(empty($mapAnnotationArrayOutput)) {
($mapAnnotationArrayOutput == "empty");
}
Change this
($mapAnnotationArrayOutput == "empty");
To this
$mapAnnotationArrayOutput = "empty";
I've seen many people write:
if( x = "foo")
and wonder why it assigns "foo" to x... but never the other way around.
if( !$mapAnnotationArrayOutput) $mapAnnotationArrayOutput = "empty";
Try putting:
print("String is empty");
In the if statement, at the moment ($mapAnnotationArrayOutput == "empty"); will have no output so you wouldn't know if the string was empty or not.
If you're trying to assign the variable the value of "empty", use:
$mapAnnotationArrayOutput = "empty";
Instead.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The problem is that the $prenume echoing works, while $comentarii doesn`t. I tried with and without quotes. If I echo $comentarii in the while loop, it echoes. I only have 1 line of text to retreive from database. Please help! Thank you !
$gaseste_elevul = "SELECT prenume_elev, comentarii
FROM elevi
WHERE kod_utilizator=1";
$gaseste_elevul_query = mysql_query($gaseste_elevul);
while($elevul = mysql_fetch_array($gaseste_elevul_query))
{
$prenume = $elevul['prenume_elev'];
$comentarii = $elevul['comentarii'];
}
if($comentarii = NULL)
{
echo "Momentan nu aveti informari pentru $prenume!";
}
else
{
echo "Mai jos aveti informarile pentru $prenume:";
echo "$comentarii";
}//sfarsit else
I also tried to do the whole if($comentarii=NULL) in the while loop, to no result.
Change
if($comentarii = NULL)
to
if($comentarii == NULL)
Your first statement sets the $comentarii to null, and that's why it doesn't echoing anything.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I recently started to try to teach myself PHP. I've only taken a beginner class in C before, so this is a little new to me.
I was fiddling around with some basic code just to practice:
<?php
$num = 0;
while ($num < 5)
{
if ($num == 1)
{
echo 'There is' . $num . ' monkey.';
}
else
{
echo 'There are ' . $num . ' monkeys.';
$num++;
}
}
?>
However, it won't run and Chrome asks me if I would like to kill the page.
Did I create an infinite loop somehow without realizing it?
Thank you!
You did create an infinite loop; you forgot to include $num++ in the original if statement (it's only in the else, so the execution gets stuck at 1).
This is a better way:
<?php
$num = 0;
while ($num < 5)
{
if ($num == 1)
{
echo 'There is' . $num . ' monkey.';
}
else
{
echo 'There are ' . $num . ' monkeys.';
}
$num++;//moved outside the if statement
}
?>