萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php給每個段落添加空格的方法

php給每個段落添加空格的方法

 這篇文章主要介紹了php給每個段落添加空格的方法,涉及PHP_EOL變量及數組與字符串的操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下

   

本文實例講述了php給每個段落添加空格的方法。分享給大家供大家參考。具體實現方法如下:

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?php //Prepends whitespace to each line of a string function white_space( $string, $whitespace ) { //Create an array from the string, each key having one line $string = explode( PHP_EOL, $string ); //Loop through the array and prepend the whitespace foreach( $string as $line => $text ) { $string[ $line ] = $whitespace . $text; } //Return the string return( implode( PHP_EOL, $string ) ); } ?>

希望本文所述對大家的php程序設計有所幫助。

copyright © 萬盛學電腦網 all rights reserved