抑制空行中的 html 回显
我有一个成员目录,其中包含姓名、地址、电话等。我想指出哪些电话号码是家庭、手机或工作电话号码,但如果条目不存在,我不希望显示家庭、工作或手机的 html拥有一个或多个这些电话号码。有没有办法抑制此信息并仅在该字段中有信息时才显示字段名称?这是包含三个电话名称的代码。
echo "<ul>\n";
echo "<li>" . $First_Name . " " . $Last_Name . "</li>\n";
echo "<li>" . $Home_Phone . " Home</li>\n";
echo "<li>" . $Cell_Phone . " Cell</li>\n";
echo "<li>" . $Work_Phone . " Work</li>\n";
echo "<li>" . "<a href=mailto:" . $Email . ">" . $Email . "</a></li>\n";
echo "<li>" . $Home_Street . "</li>\n";
echo "<li>" . $Home_City . ", " . $Home_State . " " . $Home_Zip . "</li>\n";
echo "<li>" . $Troop_Role . "</li>\n";
echo "<li>" . $Patrol . "</li>\n";
echo "</ul>";
I have a members directory that echoes name, address, phones, etc. I want to indicate which phone numbers are home, cell or work, but I don't want the html of home, work or cell to appear if the entry does not have one or more of those phone numbers. Is there a way to suppress this information and have the field name only appear if there is information in that field? Here is the code with the three phone names in it.
echo "<ul>\n";
echo "<li>" . $First_Name . " " . $Last_Name . "</li>\n";
echo "<li>" . $Home_Phone . " Home</li>\n";
echo "<li>" . $Cell_Phone . " Cell</li>\n";
echo "<li>" . $Work_Phone . " Work</li>\n";
echo "<li>" . "<a href=mailto:" . $Email . ">" . $Email . "</a></li>\n";
echo "<li>" . $Home_Street . "</li>\n";
echo "<li>" . $Home_City . ", " . $Home_State . " " . $Home_Zip . "</li>\n";
echo "<li>" . $Troop_Role . "</li>\n";
echo "<li>" . $Patrol . "</li>\n";
echo "</ul>";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 三元 运算符进行快速检查
Use a ternary operator for a quick check
在回显之前检查它们是否为空,不要使用 if 构造 回显它们和 empty
对其他变量或字段进行相同的检查
check them before echoing if they are empty do not echo them with if construct and empty
Do the same check for other variables or fields