PDA

View Full Version : php adjust the spacing and line breaks in code


jacob1986
10-07-2015, 09:39 PM
I'm supposed to learn how to adjust the spacing and line breaks in PHP code, but I don't really know where to start? I was given the example below (which I think - I have done correctly). But would it feasble for you to write some jumbled code for me to adjust and show coherently?

<?php
function formstatus ($status)
{
$valid_values = getStatusCodes () ;
if (in_array (strtolower ($status) , $valid_values)) {
return strtolower($status) ;
}
return false;
}

?>

edbr
10-07-2015, 11:44 PM
Have a look at
http://php.net/sprintf

and http://php.net/manual/en/function.str-pad.php

edbr
10-08-2015, 02:11 AM
couple of examples
<?php
$num = 'world' ;
$break = '<br> ';

$format = 'There are %s hello in the %s';
echo sprintf($format, $break,$num );
?>
<br>
<br>

<?php
$str = "Hello World";
echo str_pad($str,60,'. '.' &nbsp '.' &nbsp '.' &nbsp '.' &nbsp '.' &nbsp '.' &nbsp ' ,STR_PAD_LEFT);


?>