Setting URL in html codes to be valid
Posted: Wed Jul 25, 2007 10:55 pm
feyd | Please use
Ok, now is the real headache part for me which i'm losing hair over. CSS, i can't find a way to get the url("../image/something.gif") and change according to link. Is there a way to get those url so i could validate and insert "http://somepage.com" to replace the ".."?
From the above codes, is it a good way and is there a better way to do this?
Thanks in advance.
PS. I just start coding PHP for around 4 to 6 months on and off. Please use simple explaination if possible.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I'm trying to do a page which allow user to enter a url, retrieve the content and displaying in my page.
I know i can use iframe to do this, but i would like to use object instead. I found out that object tag (in IE) does not allow data to be from a remote server.
I don't wish to give up and plan to create a page locally by retrieving the data from the input url.
The problem arise for me is the links they had in their page. Such as image src and a href.
I solved these problems by using DOMDocument, retrieving all tags, get attributes for src and href and check if it's valid and change according.
Here is a example of my codes:Code: Select all
$body = file_get_contents($url);
$doc = new DOMDocument;
$html = mb_convert_encoding($body, 'HTML-ENTITIES', "UTF-8");
@$doc->loadHTML($html);
$allTags = $doc->getElementsByTagName("*");
foreach($allTags as $tag)
{
if($tag->hasAttribute("href"))
{
$value = $tag->getAttribute("href");
//Validate and change the attribute here
}
//Do same thing to attribute src here
}
echo $doc->saveHTML();From the above codes, is it a good way and is there a better way to do this?
Thanks in advance.
PS. I just start coding PHP for around 4 to 6 months on and off. Please use simple explaination if possible.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]