Rumah >pembangunan bahagian belakang >tutorial php >Bagaimana untuk mengalih keluar Baris Kosong dengan Berkesan dalam PHP Menggunakan Ungkapan Biasa?
Removing Blank Lines in PHP
You've encountered a challenge in removing blank lines from PHP text using regular expressions. The regular expressions you attempted have not yielded the desired results, leaving you with unwanted white space in the output.
To effectively remove blank lines, you can utilize the following regular expression:
<code class="php">preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);</code>
This regular expression thoroughly analyzes the text:
1st Capturing Group:
By using this regular expression, you can condense multiple blank lines, white space-only lines, or a combination of both into a single new line character. This gives you the desired result of removing all blank lines from your PHP text.
Atas ialah kandungan terperinci Bagaimana untuk mengalih keluar Baris Kosong dengan Berkesan dalam PHP Menggunakan Ungkapan Biasa?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!