php if empty string do something [closed] - php

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.

Related

Comparing two identical arrays returns false [closed]

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']);

mysql php - check if last variable is the same [closed]

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'];
}

PhP Error: FUNCTION [closed]

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
<?php
function me1($str) {
$hash = 'http://me1.wink.ws/me1/request.php?a=' . $str;
return $hash
}
$hi = me1('Hi');
?>
Where is my error?
Parse error: syntax error, unexpected '}' in /home/u727762781/public_html/client/me1.php on line 5
Fixed Code:
<?php
header('Content-Type: text/plain');
function me1($str) {
$hash = file_get_contents('http://me1.wink.ws/me1/request.php?a=' . $str);
return $hash;
}
$hi = me1('Hi');
echo $hi;
?>
You forgot the semi-colon at the end of the return statement.

strpos() not working as expected [closed]

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";
}
?>

How to define an Array property in a PHP class [closed]

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 9 years ago.
Improve this question
I have a following simple code but it produces syntax error on line this->players[] = 'Tom':
<?php
class club {
var $clubID = 0;
var $players=array();
function __constructor($clubID = '') {
$this->clubID = $clubID;
}
function populatePlayers() {
$this->players[] = 'Tom';
}
}
$myClub = new club(1);
$myClub->populatePlayers();
var_dump($myClub->players);
?>
It should be
$this->players[] = 'Tom';
instead of
$this->$players[] = 'Tom';
You need to add $ before the this keyword and the players variable does not need one.
Demo
try this
function populatePlayers() {
$this->players[] = 'Tom';
}

Categories