Home >Backend Development >PHP Tutorial >How to add spaces to each paragraph in php_PHP tutorial
This article mainly introduces the method of adding spaces to each paragraph in php, involving PHP_EOL variables and operations on arrays and strings The skills have certain reference value. Friends who need them can refer to them
The example in this article describes how to add spaces to each paragraph in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
?
3 4 513 14
15
|
<🎜>//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 ) ); } ?> |