Generate database table from text file with php

I host a bunch of WordPress sites, and I want to make a script that will check their version every day and if they don’t match with WordPress’ latest version, it would notify me.

Right now the easiest way I found to check their versions is looking into the wp-includes/version.php file, so I made this:

Read More

grep “$wp_version =” /home/*/public_html/wp-includes/version.php > /~/wordpress/versions.txt

The line above will be put on the cron to be executed once a day.

Now I want to make a php script that will organize each line of the above script into a table, like this:

Folder (in which the wordpress site is installed) ; Version

Then, I want the script to check if the above “Version” matches with the variable $wp_latest_version that I will set. If they match, the “Version” cell will turn green and if they don’t, the “Version” will turn red so me or and peers can know which sites we need to update.

I have sort of an idea of how I will do the last part, but right now I’m stuck in the “translate .txt file to table” process.

Any suggestions?

Also, should I use MySQL or not?

This is part of the output text that I want to translate into a table:

/home/alton/public_html/wp-includes/version.php:$wp_version = '3.5.2';
/home/boutaces/public_html/wp-includes/version.php:$wp_version = '3.4';
/home/byseacom/public_html/wp-includes/version.php:$wp_version = '3.5.2';
/home/capricho/public_html/wp-includes/version.php:$wp_version = '3.5.1';
/home/carlosva/public_html/wp-includes/version.php:$wp_version = '3.6.1';
/home/cerimoni/public_html/wp-includes/version.php:$wp_version = '3.5.1';
/home/cotaksis/public_html/wp-includes/version.php:$wp_version = '3.6.1';
/home/crisblog/public_html/wp-includes/version.php:$wp_version = '3.5';
/home/customup/public_html/wp-includes/version.php:$wp_version = '3.5.2';
/home/dentist/public_html/wp-includes/version.php:$wp_version = '3.4.2';

Related posts

Leave a Reply

1 comment

  1. foreach($lines as $line)
    {
        if(preg_match('|/home/(.+?)/public_html/wp-includes/version.php:$wp_version = '(.+?)';|', $line, $matches))
        {
            $folder = $matches[1];
            $version = $matches[2];
        }
    }
    

    Once you have the values separated from the string, write them either into a db of your choice or into a file.