1

i have bunch of htmls on my disk and I know absolute adress of each of them, now I want to make every instance of src="", href="" inside a tags like a, script, img, iframe etc. to point to absolute patch if the given path is relative.

I do not know what is the fastest way to do it, by regex, preg_match_all etc ? I want this script to have awareness of paths like "../../somefile.html".

rsk82
  • 28,217
  • 50
  • 150
  • 240
  • See http://stackoverflow.com/questions/3730933/is-there-a-way-to-keep-entities-intact-while-parsing-html-with-domdocument there is a function to do that for img, you can extend it for any tag and attribute – dev-null-dweller Oct 23 '10 at 08:40

1 Answers1

0

I think you will need a combination of regex and script, since I don't think a regex can do this on it's own

However if you get a regex to pull out a HREF with ../ then use script to count back the folders and replace with your required URL.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124