How to add space with specified string length in php

Tags: ,



I want to like add space in sting with specified string length.

For example : Hello is my string & i set string length 30 so next string should be start after length 30 so it should be like Hello Next string.

I would like to add space..

I have used following code but it’s not adding space it’s take whole character but not added space.

<?php
$fistString ="Hello World";
$secondString ="Good";
echo str_pad($fistString, 45, '  ', STR_PAD_RIGHT).$secondString;
?>

Answer

I did with my self with following way..

<?php
echo str_pad($string, 30, " &nbsp", STR_PAD_RIGHT).$secondString;

?>


Source: stackoverflow