Skip to main contentSkip to footer

Remove Spaces Between lines in files of php code

Rupak Nepali
Share:

The easiest way to remove the lines in the PHP files or in HTML files, aspx files cold fusion file, JSP file from the Dreamweaver. Likewise, we can remove the static page space like of the HTML, XSLT, CSS, XML, Javascript, XML and other as follows:

  1. Open the file
  2. Click CTRL + F
  3. Select “Current document” in “Find in” (You can also select the folder if you have multiple files)
  4. Search in “Source code”
  5. Tick “Use regular expression”
  6. Type “[rn]{2,}” (without quotes) in “Find”
  7. Type “n” (without quotes) in “Replace”
  8. Press “Replace All”

We can also replace the multiple line breaks through coding the coding is as below:

<?php
$base = array("f:/www/docs/files/");
while (!empty($base)) {
    $next = array_pop($base);
    foreach (glob($next . '*.php') as $item) {
        if (!is_dir($item)) {
            file_put_contents($item, preg_replace(array("#^s*r?n+#s", "#s*r?n+$#s", "#s*r?n+#s"), array("", "", "rn"), file_get_contents($item)));
        } else {
            $base[] = $item . '/';
        }
    }
}

echo "Removing extra lines is done";
?>

These are the two methods by which we can remove the extra lines.

Comments

Join the conversation and share your thoughts

Leave a Comment

Your comment will be reviewed before publishing.

Be the first to comment on this post!

Innovation

Let's Make Something Amazing Together

We always provide our best creative ideas at the highest level. Tell us about your project and we will make it work.

InnovateBringing innovative solutions to complex problems
AutomateStreamlining processes through automation
DominateLeading the market with exceptional results
Build Smarter and Launch FasterEfficient development for rapid deployment