Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.