hascp.blogg.se

Notepad++ remove blank lines wordpress php
Notepad++ remove blank lines wordpress php







notepad++ remove blank lines wordpress php

This has been already answered long time ago but can greatly benefit for preg_replace and a much simplified pattern: $result = preg_replace('/\s*($|\n)/', '\1', $subject) \h matches any horizontal whitespace character, and \v matches vertical whitespace. The actual list varies from one regex flavor to the next, but at minimum you can expect \s to match whatever matches.Īctually, in PHP you have a better option: $str = preg_replace('/^\h*\v+/m', '', $str) The author seems to expect \s to match just the space character ( \x20), when in fact it matches any whitespace character. I'm pretty sure that's not the desired outcome.īut most of the time it replaces two or more consecutive newlines, along with any horizontal whitespace (spaces or tabs) that lies between them, with one linefeed. So, in the special case of a string that starts with one or more blank lines, they'll be replaced with one blank line. The regex has to match either the beginning of the string ( ^*, multiline mode not set) or at least one newline ( +), followed by at least one newline ( +). The accepted answer gets the job done, but it's more complicated than it needs to be. You don't need the end-of-line anchor ( $) because you're actively matching the newline characters, but it doesn't hurt. The start-of-line anchor is necessary because without it the regex would match the newline at the end of every line, not just the blank ones. The m modifier allows ^ to match the beginning of a logical line rather than just the beginning of the whole string. Your preg_replace() won't even compile, but if you add delimiters and set multiline mode, it will work fine: $str = preg_replace('/^*+/m', '', $str) Your ereg-replace() solution is wrong because the ereg/eregi methods are deprecated. Quantifier: Between one and unlimited times, as many times as possible, giving back as needed + match a single character present in the list below \n matches a fine-feed (newline) character (ASCII 10) Quantifier: Between zero and unlimited times, as many times as possible, giving back as needed * match a single character present in the list below The above regular expression says: /(^*|+)*+/

notepad++ remove blank lines wordpress php

New line is required to split non-blank lines









Notepad++ remove blank lines wordpress php