I imported a database with product descriptions. And where there are no descriptions, there are quotation marks (") in the line. I display the list of products, and I want to make it so that if the description string is quotation marks, do not display it. However, in reality, it does not work. How to organize it?

if ($row['description'] <>'"') echo "ОписаниС: ".$row['description']."<br><br>\n"; 
  • one
    Make a var_dump such a field. Maybe there are 2 apostrophes? - vp_arth
  • Your message moved to the right target. There were not just quotes, but a space and a quotation mark. Thank! - Sergey
  • I want to note that it would be nice to find out why your empty description is indicated in such an exotic way. Find out, and no longer do so. - vp_arth

1 answer 1

To check if the string is empty is enough:

 if ($row['description']) echo "ОписаниС: ".$row['description']."<br><br>\n"; 

Or to make sure that you have at least one letter or number in the variable, and not just empty strings and / or quotes:

  $desc = $row['description']; if (preg_match('/[A-Za-zА-Π―Π°-я]]/', $desc) || preg_match('/[0-9]/', $desc)) { //Π‘ΠΎΠ΄Π΅Ρ€ΠΆΠΈΡ‚ ΠΏΠΎ мСньшСй ΠΌΠ΅Ρ€Π΅ ΠΎΠ΄Π½Ρƒ Π±ΡƒΠΊΠ²Ρƒ ΠΈΠ»ΠΈ ΠΎΠ΄Π½Ρƒ Ρ†ΠΈΡ„Ρ€Ρƒ echo "ОписаниС: ".$row['description']."<br><br>\n"; } 
  • Then if (empty($row['description'])) - Anton Shchyrov
  • @AntonShchyrov, how is it? If the field is empty, then output an empty field? - koks_rs
  • Well !empty(...) - Anton Shchyrov
  • @AntonShchyrov The result is the same, but I prefer a shorter recording. Without empty (); - koks_rs
  • 2
    the flexibility of thinking is simply amazing - Ipatiev