' $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 string to be after this link $strfile = substr( $ltrim, $npos+1 ); } return $links; } } return false; } function replaceLinks($file, $oldlinks, $newlinks) { if( is_file($file) && is_writeable($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) ) ) { // replace links $strfile = str_replace( $oldlinks, $newlinks, $strfile ); // pointer goes back to the beginning of file rewind($fp); // overwrite file with updated links $byteswritten = fwrite( $fp, $strfile, strlen($strfile) ); fclose( $fp ); return $byteswritten; } } } } return false; } ?>