1.) for html output use
print nl2br($msg);
plain text: should already be accomplished by the way you wrote it (\n would be the line break character if you had to have all statements in one line)
2.) just an example:
$msg = "chandan rishiraj tiwari";
print len_wo_spaces($msg);
function $len_wo_spaces($input) {
$token = explode(" ", $input);
foreach ($token AS $key => $val) {
$len_wo_spaces += strlen($val);
}
return $len_wo_spaces;
}
or, as laserlight suggested:
$msg = "chandan rishiraj tiwari";
print strlen(len_wo_spaces($msg));
function $len_wo_spaces($input) {
for ($i = 0; $i < strlen($input); $i++) {
if ($input{$i} != " ") {
$str_wo_spaces += $input{$i};
}
}
return $str_wo_spaces;
}
or, if you dont need the temp string:
$msg = "chandan rishiraj tiwari";
print len_wo_spaces($msg);
function $len_wo_spaces($input) {
for ($i = 0; $i < strlen($input); $i++) {
if ($input{$i} != " ") {
$str_wo_spaces++;
}
}
return $str_wo_spaces;
}