Home >Backend Development >PHP Tutorial >How to add spaces to each paragraph in php_PHP tutorial

How to add spaces to each paragraph in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:01:131147browse

How to add spaces to each paragraph in php

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

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 ) );

}

?>

1 2

3

4 5

67 8 9 10 11 12
13
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 ) ); } ?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/971953.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/971953.htmlTechArticleHow to add spaces to each paragraph in php. This article mainly introduces how to add spaces to each paragraph in php. , involving PHP_EOL variables and operation skills of arrays and strings, with certain reference...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn