Jump to content

whitespace


roonnyy

Recommended Posts

Hi guys,

I've got php function which puts 2 white space after every character in string for example: HELLO to H  E  L  O

I can't use HTML characters like '  ' (I need only white spaces between words) because I print this into PDF with FPDF and FPDF print H&nbsp&nbspE&nbsp&nbsp.....

Any ideas?

I'll apreciate any help. Thanks

Link to comment
https://forums.phpfreaks.com/topic/184530-whitespace/
Share on other sites

simple little function:

 

<?php
function add_spaces ($str)
{
$len = strlen ($str); //string length;

$c = 1; //counter to keep trailing spaces form being appended;

for ($i=0; $i<$len; $i++)
{
	if ($c == $len)
	{ $n_str .= substr ($str, $i, 1); }
	else
	{ $n_str .= substr ($str, $i, 1). '  '; }

	$c++; //increment;
}
return $n_str;
}

echo add_spaces ('hello'); //prints h  e  l  l  o;
?>

Link to comment
https://forums.phpfreaks.com/topic/184530-whitespace/#findComment-974177
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.