Assign an id
(test
) to image element and with jquery you could fetch src
attribute of image with below code.
Jquery
var srcImage = $("#test").attr("src");
Or with Javascript
var srcImage = document.getElementById("test").getAttribute("src");
Now you could perform string
operation on srcImage
if you want particular part of src
JSFiddle
https://jsfiddle.net/aq0a9jqs/
Sorry Jazz I did not notice that it was exclusively for php.
Kindly refer to question tagged by Quentin as reference. It provides multiple options on how to load/parse html content in php.
There are multiple ways to parse html from string/file/url. Once parsing is performed you could fetch elements from parsed content with supported functions. After referring to answers in tagged question I found SimpleHTMLDOMParser
easy to use.
You could you it as below for your problem in particular.
Load HTML from file/URL
$html = file_get_html('http://www.example.com/'); //Your HTML url or file
Find image with attribute id=test
$ret = $html->find('img[id=test]'); //this will work if image element has ID if you can not change html then use foreach method mentioned in documentations.
Get a attribute ( If the attribute is non-value attribute (eg. checked, selected...), it will returns true or false)
$value = $ret->src;
This is what I understood by referring to documentations here. I have not tested it. http://simplehtmldom.sourceforge.net/ and
http://simplehtmldom.sourceforge.net/manual.htm#section_find
Give it a try and see how it works out. Also refer to other possibilities from tagged question and choose whichever is easy for you. I hope it helps you. lmk.