View Full Version : Include help
Richard
01-02-2003, 03:48 PM
When I try to include an external webpage on my webpage, images from the ext. page don't load because the image locations are like ../../blah.gif not the full path. And because the ext. page is loading on mine, it looks for the image on my server and not the original one.
Is there a way to make it so the images use the full path or something to overcome this problem ?
mordred
01-02-2003, 07:04 PM
As I understand it you get the content of that page by include/require. That will simply sort-of download the output of the destination page directly into your script, as you have described. I don't know of any function that can be directly applied to your problem, but it's surely solvable, though not trivial.
You need to download the file content into a temporary file or directly into a variable, and then find all src="" attributes and replace their content via string or regular expression functions with a resolved path. Have a look at parse_url(), it could provide helpful for your task.
Richard
01-02-2003, 09:36 PM
Thanks for your reply mordred. I'm not very good at php so am unable to script most of the things you described :S
mordred
01-02-2003, 09:54 PM
Then that's perhaps a good project to start improving your PHP skills? It shouldn't be that hard, you download the file with file() into an array, and then loop through that array, and on every iteration you search for an occurrence of 'src="' and insert after that the URL's host + directory part.
And if you encounter problems, you're still free to post them here in the forum.
When I said "not trivial", I thought of a those nasty little exceptions to the rule: Other attributes that have an URL as a value, images defined in CSS files, JS script files, etc... But for a start you don't have to care for every possible issue, if you just expect a file with some bad src values.
However, perhaps there is a script on hotscripts.com or php.resourceindex.com that does exactly that. I just don't know of any, perhaps others do.
Richard
01-04-2003, 10:48 PM
Mordred, from the php manual i have made up this script (google is just an example):
<?php
$lines = file ('http://www.google.co.uk');
foreach ($lines as $line_num => $line) {
$line2=str_replace("images/", "http://www.google.co.uk/images/", "$line");
echo "$line2";
}
?>
it works, but is there a way to remove lines? for example, if there is a meta tag in a line, i want the script to remove that line?
Spookster
01-04-2003, 11:34 PM
Here is what a quick search of this forum resulted in:
http://codingforums.com/showthread.php?s=&threadid=4853&highlight=image+include
Richard
01-04-2003, 11:59 PM
Spookster thanks, but that doesn't answer my question about removing lines :(
mordred
01-05-2003, 12:58 AM
Since "lines" is actually an array, you can use all array functions from the manual to manipulate it. To delete an element from an array you can either use unset() or array_splice(), if that answers your question.
Spookster
01-05-2003, 03:26 AM
Originally posted by Richard
Spookster thanks, but that doesn't answer my question about removing lines :(
Your original question was in regards how to get the full path to the image no matter where the include file is included at. That is how you do it.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.