How to add spaces to each paragraph in php

墨辰丷
Release: 2023-03-31 18:10:02
Original
2286 people have browsed it

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template