Jump to content

erase first 2 lines of a file keeping the rest of the info..


tbare

Recommended Posts

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?

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);

...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?

<?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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.