tbare Posted December 31, 2007 Share Posted December 31, 2007 hello.. have a file contianing an array like: <?php $files = array( array( 'file'=>"family_guy_funny_moments_1.flv", 'title'=>"Family Guy Funny Moments", 'thumb'=>"family_guy_funny_moments_1_thumb.png" ), array( 'file'=>"recoil_sucks.flv", 'title'=>"Don't think she was ready for thre recoil", 'thumb'=>"recoil_sucks_thumb.png" ), //....more here ?> appending to this file is not a problem, but what i'm wanting to do is is erase the first 2 lines first (the "<?php" and "$files = array(") so i can write the data of the added file into the array... how would i trim the first 2 lines from the file? Quote Link to comment https://forums.phpfreaks.com/topic/83880-erase-first-2-lines-of-a-file-keeping-the-rest-of-the-info/ Share on other sites More sharing options...
Barand Posted December 31, 2007 Share Posted December 31, 2007 Why mess around like that? Use array_merge() include 'files_array.php'; $more_files = array ( array( 'file'=>"xxx.flv", 'title'=>"yyy", 'thumb'=>"zzz_thumb.png" ) ); $files = array_merge ($more_files, $files); Quote Link to comment https://forums.phpfreaks.com/topic/83880-erase-first-2-lines-of-a-file-keeping-the-rest-of-the-info/#findComment-426874 Share on other sites More sharing options...
tbare Posted December 31, 2007 Author Share Posted December 31, 2007 oh.. because i like to do things the hard way thanks.. i'll check that out.. Quote Link to comment https://forums.phpfreaks.com/topic/83880-erase-first-2-lines-of-a-file-keeping-the-rest-of-the-info/#findComment-426876 Share on other sites More sharing options...
tbare Posted December 31, 2007 Author Share Posted December 31, 2007 ...and on that note: i'm adding the files in a different file, (admin/update_video.php) posting info to yet a third file (admin/update_video2.php), where the original files array is in (../text_files/humor_video_random.php) how would i add to an array in a different file? Quote Link to comment https://forums.phpfreaks.com/topic/83880-erase-first-2-lines-of-a-file-keeping-the-rest-of-the-info/#findComment-426879 Share on other sites More sharing options...
Barand Posted December 31, 2007 Share Posted December 31, 2007 <?php include 'files_array.php'; include 'more_files_array.php'; $all_files = array_merge ($files, $more_files); $fp = fopen('all_files_array.php', 'w'); // write all to 3rd file fwrite ($fp, "<?php\n" . var_export($all_files, true) . ";\n?>"); fclose ($fp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83880-erase-first-2-lines-of-a-file-keeping-the-rest-of-the-info/#findComment-426978 Share on other sites More sharing options...
tbare Posted January 3, 2008 Author Share Posted January 3, 2008 danke... i decided on sensei, btw Quote Link to comment https://forums.phpfreaks.com/topic/83880-erase-first-2-lines-of-a-file-keeping-the-rest-of-the-info/#findComment-428812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.