• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1070
  • Last Modified:

Smarty/PHP remove all linebreaks before displaying document

Given a Smarty template, we would like to remove all linebreaks before displaying the document the user.

The suggested solution should be performant if possible.
0
semantique
Asked:
semantique
1 Solution
 
midhungirishCommented:
you can write a php function to remove all the line breaks from a string.. then register this function as a smarty output filter... now smarty will pass all the template outputs through this particular function before sending it to end user.....  bingo.... you get what you need.... see the attached code..
function filterCarriageReturn($tpl_output, &$smarty)
{
    $tpl_output = str_replace(chr(10), " ", $tpl_output);     //remove carriage returns
	$tpl_output = str_replace(chr(13)," ", $tpl_output);
    return $tpl_output;
}

// register the outputfilter
$smarty->register_outputfilter('filterCarriageReturn');

Open in new window

0
 
semantiqueAuthor Commented:
Thanks. Worked like a charm
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now