Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6346139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:57:36+00:00 2026-05-24T20:57:36+00:00

I want to do the following I want to create .php file (executed via

  • 0

I want to do the following

I want to create .php file (executed via cronjobs) that will paste this code $files[] = 'example.php';
to other php file (paste.php) but it has to find the lastest $files[] line like regex $files[] = '(AnythingHere)'; and after this line to paste the new line. It can have random number of pages so I have no way of knowing.

<?php

    if (!isset($php_file)) {

        $files[] = 'page1.php';

        $files[] = 'page2.php';

        $files[] = 'page3.php';

        $files[] = 'page4.php';

        $file = $files[ rand(0,count($files)) ];

I hope you guys understand what I want; can anyone help me out with this one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:57:37+00:00Added an answer on May 24, 2026 at 8:57 pm

    if you have ONLY $file[] = ‘…’ in paste.php, you can simply append to the file:

    $line = '$file[] = "pageX.php";' . PHP_EOL;
    file_put_contents('paste.php', $line, FILE_APPEND);
    

    of you want the last “page[]” enty.

    $yourNewLine = '$file[] = "pageX.php";';  // this is an example. put your "line" prm here
    $filename = 'paste.php';
    $lines = file($filename);
    $lines = array_reverse($lines)
    $found = false;
    $i = 0;
    while ( ! $found )
    {
        if ( strpos($lines[$i], '$files[] = ' === 0) ) 
        {
            $found = true;
            array_splice($lines, $i, 0, $yourNewLine.PHP_EOL);
        }   
        $i++;   
    }
    $lines = array_reverse($lines);
    file_put_contents($filename, $lines);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create URL re-write rules for following URL in htaccess. http://example.com/vedios/category/fun/ ->
I'm following this tutorial here http://www.kriesi.at/archives/create-a-multilevel-dropdown-menu-with-css-and-improve-it-via-jquery on adding a menu with jquery. I've created
Using this function I want to create a PHP navigation: function loadPage($pagename) { if
I tried to create a htaccess file that rewrites, for example the URL from
I have the following code: <? $serverurl = $_SERVER[DOCUMENT_ROOT]; $file = $serverurl.'/demo/sample_php.php'; $newfile =
I want to create a simple logfile in PHP that later can be read
I am using php. Create a file leftcolumn.php which includes following codes.. <!DOCTYPE html
I want to create the following element: <exercises xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mySchema.xsd"> If I use something
I want to create the following T-SQL statement: SELECT SUM (sa.Amount) as 'SumAmount', SUM(sa.Cost)
I want to create a view from the following two tables: Entry: entry_id entry_date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.