I am attempting to crawl through a file and insert “../../” at the beginning of every image path. Unfortunately though, the script is timing out, and since it only took a few seconds to run before this was added something tells me it is not doing what I think it should be. This is how I’m doing it:
$filedata = substr_replace(substr($filedata,$imageBeginning,1),"../../",$imageBeginning);
I am crawling entire HTML files to accomplish this, so I need an efficient solution. Any help is appreciated.
This is completely untested, but something like this:
Explanation: You are making 2 captures in the regular expression. The first is everything from the start of the
imgtag to the start of thesrcattribute. The second is thesrcattribute value and everything after it. Then you just insert “../../” in the middle in the replacement.http://php.net/manual/en/function.preg-replace.php