在php中回显带有标签的图像url
我之前问过一个关于如何从 html 页面回显图像 url 的问题。我可以成功地做到这一点,但如何进一步缩小范围,以便只显示以某个短语开头的图像网址,此外,如何在它们周围添加图像标签,以便图像显示为图像而不仅仅是文本?
例如,我只想列出以 http://photos.website.com 开头的图像。
编辑:我忘了提及这是用于迭代图像的代码:
foreach($images as $image) {
echo $image->getAttribute('src') . '<br />';
}
I have previously asked a question on how to echo the url of images from an html page. I can do this successfully but how can I narrow this down further so only images urls beginning with a certain phrase are shown, furthermore how can I add an image tag around them so the images are displayed as images and not just text?
e.g I only want to list images beginning with http://photos.website.com.
edit: I forgot to mention this is the code used to iterate through the images:
foreach($images as $image) {
echo $image->getAttribute('src') . '<br />';
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须添加一个条件来测试
$image->getAttribute('src')
的内容。要测试一个字符串是否被另一个字符串存在,可以使用
strpos
函数,它返回干草堆中针的位置 - 在这里,您希望该位置为0 (即字符串的第一个字符)。
You will have to add a condition that tests the content of
$image->getAttribute('src')
.To test if a string beings by another, a possibility is to use the
strpos
function, which returns the position of the needle in the haystack -- here, you want that position to be0
(i.e. the first character of the string).简单:
添加标签:
Simple:
And to add tags: