Ok, the situation is simple (i hope!)
I am working locally (xampp) and in my .php file i've got the following img elements :
<img src="http://example.com/images/project-1/image1.jpg"/>
<img src="http://example.com/images/project-1/image2.jpg" />
<img src="http://example.com/images/project-1/image3.jpg" />
How can I make it to run a search and replace function (with php if possible) that will fulfil the following:
1) On page load to scan the whole document and find all the above images that don't appear (broken links)
2) IF from the above we find broken images , then to replace only the part that says "http://example.com" with "http://127.0.0.1/projectfile".
So what I want is to scan the whole document for broken images and if I find x of them then to replace the src from this:
src="http://www.example.com/images/project-1/image1.jpg"
with this:
src="http://127.0.0.1/project/images/project-1/image1.jpg"
I want to do this for all the images automatic, and not manually.
Currently I am struggling to do this with jQuery but I probably I am gonna need PHP because I need to navigate to the previous folders,scan dir etc etc
Thank you for you support! Any ideas or tips?
So far what I tried and succeeded partially as I said above is to search/replace with jQuery:
$('img').attr('src',function(i,e){
return e.replace("http://example.com","http://127.0.0.1");
})
,which ignores the live website src folder and sticks directly to the local folder but I need to make it a bit more clever :)