Jump to content

Recommended Posts

Had some JS that wasn't working, and turned out I had a whitespace at the end of a PHP file.  To fix it and other bad files, came up with the following.  See any problems with it?  Yea, I know that it surely could be done at the command line, but made me feel safer doing it this way.  Also, maybe should just get rid of the closing PHP tags altogether, but still have the issue with opening tags.  Thanks

<?php
$dir=dirname(dirname(dirname(__FILE__))).'/classes';
echo($dir."\n\n");
$dir = new DirectoryIterator($dir);
foreach ($dir as $fileinfo) {
    if (!$fileinfo->isDot() && $fileinfo->getExtension()=='php') {
        $file=$fileinfo->getPathname();
        $content=file_get_contents($file);
        if(ctype_space(substr($content, 0, 1)) || ctype_space(substr($content, -1))){
            echo("TRIM: $file\n");
            file_put_contents($file, trim($content));
        }
    }
}
?>
Link to comment
https://forums.phpfreaks.com/topic/300891-remove-whitespace-from-php-file/
Share on other sites

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.