How do you split a text field/textarea by line breaks?

Sometimes you want to provide a simple way for users to enter multiple values.  Perhaps the simplest way for the user is to understand is allow them to enter new values on each line.  Historically that’s how Internet Explorer allowed you to configure multiple home pages: 1 per line. It’s a tested method that works.

However, how do you then process the information?  There are lots of possiblitities, however I prefer an answer I found was posted back in 2011: Use preg_split().

preg_split( '/\r\n|[\r\n]/', $_POST[ 'yourtextarea' ], PREG_SPLIT_NO_EMPTY )

By using regex, this function will handle entries from various platforms. You don’t need to worry about whether is just a carriage return or just a linefeed or even both at the end of a line.  The split is handled nicely and you get an array returned. It will even, by adding an optional third parameter, ignore any blank lines.  Once you have your value returned, you can write the array out to an option record, or process it however you like.

Once you have the array loaded from your DB, how do you split it into multiple lines again? That’s simple: Use implode().

implode( "\n",  $myarray );

Hope that helps someone!

WordPress and NotePad++

I use NetDrive and NotePad++ to do my WordPress Development, but I’ve customized NPP slightly along the way.
I’ve added the following functions:
Alt-F3 – Search the WordPress codex for the word at the cursor in the editor (usually for filters and actions etc)
Alt-F5 – Look up the word at the cursor as a function on the WordPress Developer wiki (will show the source)
Alt-F6 – Look up the word at the cursor as a function in the WordPress codex (will include examples)

To do this I edited shortcuts.xml

You can edit this file by closing notepad++ and then hitting WindowsKey+R and pasting in: notepad %AppData%\Notepad++\shortcuts.xml
And pressing enter.

 <Shortcut id="41014" Ctrl="no" Alt="no" Shift="yes" Key="116" />
 <Macro name="Trim Trailing and save" Ctrl="no" Alt="yes" Shift="yes" Key="83">
 <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
 <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
 <Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox &quot;$(FULL_CURRENT_PATH)&quot;</Command>
 <Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">iexplore &quot;$(FULL_CURRENT_PATH)&quot;</Command>
 <Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">chrome &quot;$(FULL_CURRENT_PATH)&quot;</Command>
 <Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="70">safari &quot;$(FULL_CURRENT_PATH)&quot;</Command>
 <Command name="Get php help" Ctrl="no" Alt="yes" Shift="no" Key="112">$(CURRENT_WORD)</Command>
 <Command name="Google Search" Ctrl="no" Alt="yes" Shift="no" Key="113">$(CURRENT_WORD)</Command>
 <Command name="Codex Search" Ctrl="no" Alt="yes" Shift="no" Key="114">$(CURRENT_WORD)</Command>
 <Command name="WP Developer Function" Ctrl="no" Alt="yes" Shift="no" Key="116">$(CURRENT_WORD)/</Command>
 <Command name="Codex Function" Ctrl="no" Alt="yes" Shift="no" Key="117">$(CURRENT_WORD)</Command>
 <Command name="Open containing folder" Ctrl="no" Alt="no" Shift="no" Key="0">explorer $(CURRENT_DIRECTORY)</Command>
 <Command name="Open current dir cmd" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /K cd /d $(CURRENT_DIRECTORY)</Command>
 <Command name="Open in another instance" Ctrl="no" Alt="yes" Shift="yes" Key="79">$(NPP_DIRECTORY)\notepad++.exe $(CURRENT_WORD) -nosession -multiInst</Command>
 <PluginCommands />
 <ScintillaKeys />


How to find Joomla WordPress or Drupal version from Linux CLI

I was about to rewrite some of these queries again, and decided to google instead.  I found this page with them already written:

So this too gets stored away in my cave.  Enjoy:

WordPress version


find /home/*/public_html/ -type f -iwholename “*/wp-includes/version.php” -exec grep -H “\$wp_version =” {} \;


find /var/www/vhosts/*/httpdocs/ -type f -iwholename “*/wp-includes/version.php” -exec grep -H “\$wp_version =” {} \;

Windows/IIS (default path) with Powershell:

Get-ChildItem -Path “C:\inetpub\wwwroot\” -Filter “version.php” -Recurse | Select-String -pattern “\`$wp_version =”


Joomla! 1/2/3 version and release:


find /home/*/public_html/ -type f \( -iwholename ‘*/libraries/joomla/version.php’ -o -iwholename ‘*/libraries/cms/version.php’ -o -iwholename ‘*/libraries/cms/version/version.php’ \) -print -exec perl -e ‘while (<>) { $release = $1 if m/ \$RELEASE\s+= .([\d.]+).;/; $dev = $1 if m/ \$DEV_LEVEL\s+= .(\d+).;/; } print qq($release.$dev\n);’ {} \; && echo “-“


find /var/www/vhosts/*/httpdocs/ -type f \( -iwholename ‘*/libraries/joomla/version.php’ -o -iwholename ‘*/libraries/cms/version.php’ -o -iwholename ‘*/libraries/cms/version/version.php’ \) -print -exec perl -e ‘while (<>) { $release = $1 if m/ \$RELEASE\s+= .([\d.]+).;/; $dev = $1 if m/ \$DEV_LEVEL\s+= .(\d+).;/; } print qq($release.$dev\n);’ {} \; && echo “-“


Drupal version:


find /home/*/public_html/ -type f -iwholename “*/modules/system/” -exec grep -H “version = \”” {} \;


find /var/www/vhosts/*/httpdocs/ -type f -iwholename “*/modules/system/” -exec grep -H “version = \”” {} \;


Latest version information:



What does “Is this ok [y/d/N]:” mean?

When installing new software using yum, you will occasionally get the the option of “Is this ok [y/d/N]:”  Everyone knows recognizes Yes and No, but the option d may have thrown you for a loop.

“d” simply stands for download only.  If you were to do this from the commandline you’d use this:

yum –download-only

Occasionally this is useful if you are prepping a resource, like a thumb drive, with all of the RPMs that you standardly install.  You might also want to have the RPMs available for switching between versions of software.  I’m sure there are many more reasons too.

Hopefully this has answered your question.

Advanced Google Search Operators

Sometimes a simple Google search won’t do. Today I needed to find some malformed URLs in a site.   I couldn’t remember how to search for specific text in a URL.

I had a hard time finding the Google documentation of search commands this morning.  It I needed the allinurl: function.

I don’t want to have to search that hard again so here is the documentation in my Code Cave:

Search Service Search Operators
Web Search allinanchor:allintext:allintitle:allinurl:cache:define:filetype:id:inanchor:info:intext:intitle:inurl:link:related:site:
Image Search allintitle:allinurl:filetype:inurl:intitle:site:
Groups allintext:allintitle:author:group:insubject:intext:intitle:
Directory allintext:allintitle:allinurl:ext:filetype:intext:intitle:inurl:
News allintext:allintitle:allinurl:intext:intitle:inurl:location:source:
Product Search allintext:allintitle:

Source and additional information:

Finding large files on a Linux server

Here are a couple commands you might find useful.

This command finds files that are larger than half a gig:

find / -type f  -size +500M -exec ls -lh {} \;

This command finds files that are larger than 1 gig:

find / -type f  -size +1G -exec ls -lh {} \;

This command finds files that are larger than 1 gig excluding the home directory which might be on a different mount. (notice the removal of the -type f so that the not works on paths):

find / -not \( -path /home -o -path /boot -o -path /tmp \)  -size +1G -exec ls -lh {} \;


How to Fix: After upgrading WHMCS: Down for Maintenance An upgrade is currently in progress

I recently came across an issue I’d not seen before. After performing what I thought was a proper upgrade, I found that my support and sales portal was displaying the error:

Down for Maintenance (Err 2)
An upgrade is currently in progress… Please come back soon…

I found several difference references to this error on the web. The one detail that I was able to glean was that this error usually occurs when the files are updated, but the database is not. This was the case in my situation. It turns out that I caused my own problem. The key to the mystery is that the files to perform the database upgrade are actually part of the “install” directory.

The instructions for a full upgrade are  here:

Basically  you just:

  1. Extract the files
  2. Rename the admin and cron directories as needed
  3. Copy those files over the existing installation
  4. Visit the site and follow the upgrade instructions, if any.

My problem was that #4  includes an error at the end that tells you the install directory still exists, delete it.  Being a guy who likes to optimize a process as much as possible, I was deleting the install directory before copying  in the files.  This process worked great 99% of the time.  However, eventually they changed the database structure from 5.2.13 to 5.2.14 or 5.2.15.  THEN the result was that the WHMCS software could not upgrade the database. and I got the wonderful WHMCS Down for Maintenance error.

So really the steps should be:

  1. Extract the files
  2. Rename the admin and cron directories as needed
  3. Copy those files over the existing installation
  4. Visit the site and follow the upgrade instructions, if any.
  5. Delete the install directory when prompted.

At that point, everything should work fine.   At least it did for my particular incarnation of the problem.  I hope it solves your issues too.

How to quickly update WHMCS on WiredTree hosting and others.

NOTE: This script has been updated to remove the premature deletion of the install directory.

Over the last month or two, WHMCS has been updated many times. This is a GOOD THING, but it can be annoying to go through the normal update process every week or two.

So, I created a small function that I’ve added to /etc/bashrc on my server.

It does the following:
1. Verifies the script is running from the right server.
2. Changes directories to the location where I have WHMCS installed.
3. Removes any files and folders from a previous update
4. Downloads the latest update from the password protected WiredTree repository
5. Unpacks it
6. Renames the admin directory to a new name for security purposes (you may need to do the cron dir too)
7. Changes the owner and group of the new files to be the one required for this website.
8. Copies in all of the new files, overwriting what is there.

So updates now take a few seconds rather than 20 distracting minutes. Maybe you will find this useful.

Here is the function I added to /etc/bashrc:


function upwhmcs(){
  curhostname=$(hostname -s)

  if [ "${curhostname}" == "$desiredhost" ]; then
    rm -Rf whmcs
    rm -f
    unzip -o
    cd whmcs
    cp -Rf * ../www
    cd ../www
  echo "Wrong Server. Update skipped"


To use that listing you need to replace the following text
REPLACE_WITH_HOSTNAME – Replace this with what you get when you run ‘hostname -s’ from the command line.
REPLACE_WITH_DIRNAME – Replace this text with the directory of your whmcs installation. Maybe it is /home/whmcs/ or /home/hosting/ or /home/sales/
REPLACE_WITH_USERNAME – This should become the username that WiredTree gave you to login and get WHMCS updates
REPLACE_WITH_PASSWORD – This should become the password that WiredTree gave you to login and get WHMCS updates
REPLACE_WITH_ADMIN_DIR_NAME – This is the custom name of the admin directory on your server. If you just use admin, delete this mv line entirely.
REPLACE_WITH_DIROWNER – This is quite likely the same value as REPLACE_WITH_DIRNAME

This script assumes that you have WHMCS installed as its own website/subdomain. You can probably adjust it to your needs if you run it in a sub-directory. If you make this customization, send it back to me and I’ll add it to the article.

After the upgrade process, you must visit the site, follow the update steps and then go back and delete the “install” directory from the installation.  That should do it!

How To: List the lines that exist in one file and not another in Linux or Windows Command Line

This solution uses grep.

Grep is a search tool that exists by default in just about every Linux installation. You can also search Google for Windows Grep.

for a Demo, Here is FileA.txt

1. In Both
2. In Both
3. In Both
4. In File A Only
5. In Both
0. Out of Order In Both
-1.  Out of Order In A Only
In A only

Here is FileB.txt

1. In Both
2. In Both
3. In Both
4. In File B Only
5. In Both
0. Out of Order In Both
-1.  Out of Order In B Only
In B only

To show lines that only exist in File B and not in A. Do this:

# grep -v -xFf FileA.txt FileB.txt

4. In File B Only
-1.  Out of Order In B Only
In B only

To show lines that only exist in File A and not in B. Do this:

# grep -v -xFf FileB.txt FileA.txt

4. In File A Only
-1.  Out of Order In A Only
In A only


In windows, Grep you can drop the capital F from the command line. But it really shouldn’t matter.

The command line arguments are:

-v = Reverse the compare so you get what doesn’t match instead of what does

-x = Compare entire lines at a time instead of characters

-F = Do not parse the contents of each line for any mid-line regex commands

-f = Compare the specified files


Hope that helps someone!

How to fix: WordPress updates and plugin installs require FTP login but shouldn’t.

WordPress is generally very good about working under any server situation you put it in. It even has fall back code if the preferred server settings are not available.

The plugin and update installation code is one example of this. If WordPress doesn’t have the rights to directly update files, it will ask you for FTP login information.

However, there are times when you KNOW the permissions are correct to allow Apache to update files and WordPress doesn’t detect it and insists on FTP. This should be extremely rare. However if you ever do come across this circumstance you can force WordPress to override this behavior and use direct updates.

Just add these lines to wp-config.php:

define( ‘FS_METHOD’, ‘direct’ );
define( ‘FS_CHMOD_DIR’, 0777 );
define( ‘FS_CHMOD_FILE’, 0777 );

You can read more about these constants on the WordPress Codex.