Alex Lord
asked on
insert domain into src string in php
"<p><img alt="" src="uploaded_files/12/images/_gzyefj8rwhokhhzgprzltl72ejkfbmt4t8yenimkbvvk0ktmf0xjctabnaljim9.jpg" style="height:285px; width:285px" /></p>
"
this is my string in php, i need to add into it but i dont want to delete it, for example, i need to alter the url within the src, it is missing the the http//:Domain it suspose to be
https//:Domain.com/uploade
im using php
ASKER
$html = new DOMDocument();
$html->loadXML($_POST['quick_email']);
$img = $html->getElementsByTagName('img')[0];
$img->setAttribute('src', $_SERVER['HTTP_HOST'] . $img->getAttribute('src'));
$content = $html->saveHTML();
my error
[12-Apr-2019 09:58:43 Europe/London] PHP Fatal error: Uncaught Error: Call to a member function setAttribute() on null in /Applications/MAMP/htdocs/
Stack trace:
#0 {main}
thrown in /Applications/MAMP/htdocs/
ASKER
sorry im stupid lol my bad i got it now
No Problem, is it working now?
ASKER
yes it is working, how i just need to implement a condition not to do these commands if no img is present.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Zakaria Acharki
thank you for your help, great learning experience
thank you for your help, great learning experience
Glad to help, welcome anytime.
Open in new window