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代码实现的说明能为您的程序开发工作提供有价值的帮助。