Log in

View Full Version : Resolved PHP help needed PLZ!



tgallagher26
04-08-2009, 06:04 PM
Ok so I have several functions I have been working all morning to combine.

First to combine my old list with a the new list.


$old_list = 'top100.txt';
$new_list = file_get_contents('http://kywordpro.com/top100print.php');
file_put_contents($old_list, $new_list, FILE_APPEND | LOCK_EX);

Second I want to replace a few items from the updated list


$updated_list = 'top100.txt';
$search = array(' ');
$replace = array('+');
$subject = $updated_list;
$newlyupdated_list = str_replace($search, $replace, $subject);


Then I want to organize my newly updated list



$list = $newlyupdated_list;
$list = array_map("strtolower", $list);
$list = array_unique($list);
sort($list, SORT_STRING);
file_put_contents('perfect_list.txt', implode('', $list));


Can anyone help me get this to work properly?

Tim..

Nile
04-08-2009, 07:43 PM
Well, you can make one files for past lists, and one file for the current list. Replace:


<?php
$old_list = 'top100.txt';
$new_list = file_get_contents('http://kywordpro.com/top100print.php');
file_put_contents($old_list, $new_list, FILE_APPEND | LOCK_EX);
?>

With:


<?php
$target_file = 'top100.txt';
$all_data = "past100.txt";
$all_data_file = trim(file_get_contents($all_data)."\n".file_get_contents($target_file));
$split = explode("\n", $all_data_file);
$split = array_unique($split);
sort($split);

$file = fopen($all_data, 'w');
fwrite($file, trim(implode("\n", $split)));
fclose($file);

$file = fopen($target_file, 'w');
fwrite($file, trim(file_get_contents('http://kywordpro.com/top100print.php')));
fclose($file);
?>