php - Get current image url - php
问题描述
I'd like to pass the current img
src
to a function I'm working on (to get more data from a database)
Is there a simple way to grab the src
from within the img
tag?
I'd like to do this:
<img src="http://example.com/images/1.jpg" alt="amazing image" data="<?php echo( get_extra_data($img_src) ); ?>" />
Rather than this:
<img src="http://example.com/images/1.jpg" alt="amazing image" data="<?php echo( get_extra_data("http://example.com/images/1.jpg") ); ?>" />
I'd like to dynamically get the src
from the current img
rather than having to have the url twice if that makes sense.
In other words, could the function get_extra_data()
reference the img
element it was called from?
This is because I'd like to just paste data="<?php echo( get_extra_data($img_src) ); ?>"
into the exsisting image elements I need it on.
解决方案
推荐阅读
- scala - 将信息从一个列表合并到另一个 Scala
- javascript - pngjs 库中的方法在 Node.js 中的行为很奇怪
- java - 为什么 toString 方法在我的优先队列代码中不起作用?
- php - 搜索并获取多维数组中的键
- spring-boot - Keycloak 总是返回 401 - 用于微服务的 Zuul api 网关
- go - 位移 << 和乘法 * 优先级
- excel - 如何使用 VBA 将一张纸上的 3 个单元格组合成另一张纸上的 1 个单元格?
- ios - 从用户通知中打开设置 URL?
- vba - 如何在 MS Project 中执行查询/访问共享点列表?
- scala - org.apache.spark.sql.AnalysisException:无法解析:从嵌套 json 读取数据时