php如何设置空格

小编给大家分享一下php如何设置空格,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

php设置空格的方法:1、创建一个PHP示例文件;2、通过“function white_space( $string, $whitespace ){...}”方法设置空格即可。

本文操作环境:windows7系统、PHP7.1版、DELL G3电脑

php给每个段落添加空格的方法

本文实例讲述了php给每个段落添加空格的方法。分享给大家供大家参考。具体实现方法如下:

<?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如何设置空格”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!