MrLarkins Posted August 18, 2009 Author Share Posted August 18, 2009 please explain how you dealt with the spaces <?php '~<SCRIPT LANGUAGE="Javascript"><!--\s*document\.write\(unescape\("~i', '~"\)\);//--></SCRIPT>~i', '~<SCRIPT LANGUAGE="Javascript"><!--\s*document\.write\(unescape\("~i', '~<SCRIPT LANGUAGE="JavaScript"><!--\s*eval\(unescape\("document\.write=null;~i' ?> Link to comment https://forums.phpfreaks.com/topic/170280-solved-using-php-and-urldecode-on-multiple-pages-starting-from-scratch/page/2/#findComment-900541 Share on other sites More sharing options...
thebadbad Posted August 18, 2009 Share Posted August 18, 2009 Of course. I converted the strings to regular expression patterns, escaping special chars like dots and parentheses. I also made the searches case insensitive with the i modifier, and substituted the spaces you had with \s*, matching zero or more whitespace characters. You got it working? Link to comment https://forums.phpfreaks.com/topic/170280-solved-using-php-and-urldecode-on-multiple-pages-starting-from-scratch/page/2/#findComment-900761 Share on other sites More sharing options...
MrLarkins Posted August 18, 2009 Author Share Posted August 18, 2009 yes, and thank you to everyone that helped. this was for converting a student edition textbook from cd to my class website. Now our algebra1 students can use the web to access their textbook, instead of checking out a cd from me. here's the final code <?php function rglob($pattern, $flags = 0, $path = '') { if (!$path && ($dir = dirname($pattern)) != '.') { if ($dir == '\\' || $dir == '/') { $dir = ''; } return rglob(basename($pattern), $flags, $dir . '/'); } $paths = glob($path . '*', GLOB_ONLYDIR | GLOB_NOSORT); $files = glob($path . $pattern, $flags); foreach ($paths as $p) { $files = array_merge($files, rglob($pattern, $flags, $p . '/')); } return $files; } $replace = array( '~<script>\s*if \(top\.phsn_ISBNID != \'0130378925\'\) \{\s*window\.location ="/";\s*}\s*</script>~i' '~<SCRIPT LANGUAGE="Javascript"><!--\s*document\.write\(unescape\("~i', '~"\)\);//--></SCRIPT>~i', '~<SCRIPT LANGUAGE="JavaScript"><!--\s*eval\(unescape\("document\.write=null;~i' ); foreach (rglob($_SERVER['DOCUMENT_ROOT'] . '/algebra1/*.html') as $file) { $data = urldecode(file_get_contents($file)); $data = preg_replace($replace, '', $data); file_put_contents($file, $data); } echo "Done"; ?> and what it does is convert html files from urlencoded to regular and then strips off all of the javascript crap it needed to run from the cd. Link to comment https://forums.phpfreaks.com/topic/170280-solved-using-php-and-urldecode-on-multiple-pages-starting-from-scratch/page/2/#findComment-900857 Share on other sites More sharing options...
thebadbad Posted August 18, 2009 Share Posted August 18, 2009 Glad it works. I don't know if it's just in the code you posted here, but you're missing a comma after the first element in the $replace array. Link to comment https://forums.phpfreaks.com/topic/170280-solved-using-php-and-urldecode-on-multiple-pages-starting-from-scratch/page/2/#findComment-900869 Share on other sites More sharing options...
MrLarkins Posted August 18, 2009 Author Share Posted August 18, 2009 yes, i saw that too. Link to comment https://forums.phpfreaks.com/topic/170280-solved-using-php-and-urldecode-on-multiple-pages-starting-from-scratch/page/2/#findComment-900942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.