How to check whether a string is empty in PHP

2 Answers

0 votes
$s = "";

if (empty($sg)) {
  echo "Empty";
} else {
  echo "Not empty";
}




/*
run:

Empty

*/

 



answered Feb 22, 2021 by avibootz
0 votes
$s = "";

if (strlen($s == 0)) {
  echo "Empty";
} else {
  echo "Not empty";
}




/*
run:

Empty

*/

 



answered Feb 22, 2021 by avibootz

Related questions

8 answers 749 views
1 answer 311 views
3 answers 404 views
1 answer 258 views
3 answers 417 views
3 answers 432 views
...