rendered paste body<?php function findLinks($file) { if( is_file($file) ) { $links = array(); // get whole file into a string if( $strfile = file_get_contents($file) ) { while( $trim = stristr( $strfile, "href=" ) ) { // strip "href=" from link $ltrim = substr( $trim, 5 ); // find out how links are enclosed switch( $ltrim[0] ) { case '"': // "http..." $delim = '"'; $ltrim = substr( $ltrim, 1 ); break; case "'": $delim = "'"; // 'http...' $ltrim = substr( $ltrim, 1 ); break; default: $delim = ' '; // http... (no enclosure) } // If no enclosure is found, not even a space, then use '>' $npos = strpos( $ltrim, $delim ); $opos = strpos( $ltrim, ">" ); if( $npos > $opos || $npos == false ) $npos = $opos; // finish trimming using the position of the end delimiter $rtrim = substr( $ltrim, 0, $npos ); // add link to array $links[] = $rtrim; // update the original file (as string) to be after this link $strfile = substr( $ltrim, $npos+1 ); } return $links; } } return false; } function replaceLinks($file, $oldlinks, $newlinks) { if( is_file($file) ) { // make sure we are supplied a newlink for every oldlink if ( count($oldlinks) == count($newlinks) ) { // open file for reading and writing $fp = fopen($file, 'r+'); if( $fp ) { // get whole file into a string if( $strfile = fread($fp, filesize($file) ) ) { $strfile = str_replace( $oldlinks, $newlinks, $strfile ); rewind($fp); $byteswritten = fwrite( $fp, $strfile, strlen($strfile) ); fclose( $fp ); return $byteswritten; } } } } return false; }?>