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

yipeiwu_com6年前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程序设计有所帮助。

相关文章

继续收藏一些PHP常用函数第1/2页

复制代码 代码如下: <? function GetIP() { //获取IP if ($_SERVER["HTTP_X_FORWARDED_FOR"]) $ip = $_SERV...

php checkdate、getdate等日期时间函数操作详解

checkdate($month,$date,$year)   如果应用的值构成一个有效日期,则该函数返回为真。例如,对于错误日期2005年2月31日,此函数返回为假。   在日期用于计...

PHP在字符串中查找指定字符串并删除的代码

$a = "abcababa"; $count=strpos($a,"ab"); $str=substr_replace($a,"",$count,2); 输出结果:cababa 代码虽...

thinkphp备份数据库的方法分享

貌似THINKPHP没有备份数据库的方法,所以我自己写了一个,数据库连接和事务处理用的是pdo,如果有需要的可以联系我,写个mysql或者mysqli的 复制代码 代码如下: <&...

PHP最常用的2种设计模式工厂模式和单例模式介绍

1.工厂模式 主要作用是降低耦合度。 复制代码 代码如下: abstract class Operation{ abstract public function getValue($nu...