首页 > 解决方案 > 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.

标签: phpimagedynamicsrc

解决方案


推荐阅读