if 语句在一行 if poss
我正在使用生成的 ID 打印图像。但是我想检查一下该图像是否存在,以及它是否不打印 no-image.jpg...
<img src="phpThumb/phpThumb.php?src=../public/images/'.$row["id"].'/th.jpg&w=162" alt="" width="162" />
如果可以将其保留在一行上,那就太好了。任何帮助将不胜感激。
I am printing an image using an ID which is generated. however i wanted to do a check to see if this image exists and if it doesnt print no-image.jpg instead...
<img src="phpThumb/phpThumb.php?src=../public/images/'.$row["id"].'/th.jpg&w=162" alt="" width="162" />
It would be great if this could be kept on one line is possible. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Kristopher Ives 所说的,以及 file_exists:
顺便说一句,你的代码片段不太可能工作,因为你似乎是将纯 HTML 输出和 PHP 结合在一起,而不将 PHP 放入
What Kristopher Ives says, and file_exists:
btw, your snippet is unlikely to work, as you seem to be combining plain HTML output and PHP without putting the PHP into
<? ?>
我的建议实际上是从 html 标签本身抽象出决策,在一个不输出 html 的单独的 php 逻辑块中...这是一个简短的示例,假设您没有使用模板引擎或 MVC 框架。
My recommendation would actually be to abstract the decision making from the html tag itself, in a separate block of php logic that is not outputting html...here is an abbreviated example that assumes you are not using a template engine, or MVC framework.
哇,这个问题被问了很多,也得到了很多回答:
http://en.wikipedia.org/wiki/Ternary_operation
你可以这样做:
Wow, this question gets asked and answered a lot:
http://en.wikipedia.org/wiki/Ternary_operation
You could do it by: