Home  >  Article  >  Backend Development  >  How to add spaces to each paragraph in php

How to add spaces to each paragraph in php

墨辰丷
墨辰丷Original
2018-06-12 11:22:332277browse

This article mainly introduces the method of adding spaces to each paragraph in PHP, involving PHP_EOL variables and operation skills of arrays and strings. It has certain reference value. Friends in need can refer to this article

The example describes how to add spaces to each paragraph in PHP. The specific implementation method is as follows:

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

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

Related recommendations:

Principles and usage of encryption and decryption in php

How to format phone numbers using regular expressions in php

php method to shut down the computer using a mobile phone

The above is the detailed content of How to add spaces to each paragraph in php. For more information, please follow other related articles on the PHP Chinese website!

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