Does anybody out there have a clue how this could be done?
I have a page that reads out HTML from files and echo the HTML into the site.
$handle = fopen($FilePath, "r");
$contents = fread($handle, filesize($FilePath));
fclose($handle);
In this HTML page there can be img tags with norwegian charracters (øæå) i want to rewrite these img tags so that the norwegian charracters are replaced with charracters that work with Firefox. It works in IE and Opera.
If i do this to the file that is read out to $contents
$contents = str_replace("å", "%c3%a5", $contents);
$contents = str_replace("ø", "%c3%b8", $contents);
$contents = str_replace("æ", "%c3%a6", $contents);
i get the img tags to work. But then all the text in the document is also turned into %c3%a6 and not readable.. :-(
So i only want to change the charracters inside the img tag.
Want the link from this:
<img width=209 height=149
src="Trådløst nettverk/Trådløs%20guide%20windows%20XP-filer/image002.jpg" align=left hspace=12>
to this
<img width=209 height=149
src="Tr%c3%a5dl%c3%b8st nettverk/Tr%c3%a5dl%c3%b8s%20guide%20windows%20XP-filer/image002.jpg" align=left hspace=12>
i have tryed this
$contents = preg_replace('/\<img (.*?)\>/is', "<img ".urlencode("$1").">", $contents);
and this
function url_encode($matches){
return "<img$matches[1] src=\"". str_replace(array("æ", "ø", "å"), array("%c3%a5", "%c3%b8","%c3%b8"), $matches[2]) ."\"$matches[3]>";
}
$contents = preg_replace_callback("#\<img(.*?) src=\"(.*?)\"(.*?)\>#", "url_encode", $contents);
and it did not work..
This is starting to "bug" me bigtime, so if anyone have a clue PLEASE HELP!