Re: [PHP] Newline and tab characters



2007. 03. 26, hétfő keltezéssel 13.58-kor Zoltán Németh ezt írta:
2007. 03. 26, hétfő keltezéssel 13.54-kor Arno Kuhl ezt írta:
I've just noticed that "\r\n" and "\t" characters create a space when
rendered in the browser (tested in IE and Firefox). I'd always thought the
browser would ignore these characters. This wouldn't normally be a problem
but the wysiwyg html editor in the cms I'm using tries to be friendly by
formatting the html code, so something like

<span style=\"COLOR: #af0e14\">get</span><span style=\"COLOR:
#333333\">online</span>

becomes

\r\n\t\t<span style=\"COLOR: #af0e14\">get</span>\r\n\t\t<span
style=\"COLOR: #333333\">online</span>

and instead of being displayed as getonline it's displayed as get online.

Is there a simple way to sort this out or do I need to create a function to
strip these characters before display, checking first that they don't occur
within a <pre> tag in which case I mustn't strip them.

why not strip them before storing the html content into the DB?
that way you need to strip them only once, while if you strip them on
display you need to strip them once for each request.
and you don't need checking with <pre> tags and stuff.
just do a
str_replace(array("\n", "\r", "\t"), "", $text);
on it and that's all

err, sorry I misunderstood your sentence about the <pre> tags...
yeah, you should somehow avoid replacing within <pre> tags. maybe in
first step find all <pre> tags, save their contents in an array, then do
the str_replace, and after that restore the <pre> tags contents with
preg_replace

greets
Zoltán Németh


greets
Zoltán Németh


TIA
Arno


.



Relevant Pages

  • Re: Limiting HTML char count code with php.
    ... I want the output text length to be limited not the tags. ... Well if I can limit the number of characters it is easier to display. ... but I only want to truncate characters that will be ...
    (comp.lang.php)
  • Re: Limiting HTML char count code with php.
    ... I want the output text length to be limited not the tags. ... Well if I can limit the number of characters it is easier to display. ... but I only want to truncate characters that will be ...
    (alt.php)
  • Newline and tab characters
    ... rendered in the browser. ... browser would ignore these characters. ... strip these characters before display, checking first that they don't occur ... within a tag in which case I mustn't strip them. ...
    (php.general)
  • Re: [PHP] Newline and tab characters
    ... rendered in the browser. ... browser would ignore these characters. ... within a tag in which case I mustn't strip them. ... display you need to strip them once for each request. ...
    (php.general)
  • Re: [Strips] Heh, this applies so broadly
    ... One other strip I was going to mention was 'Jack', ... about it's titular and supporting characters. ... local anime club and it was more than a little amusing in places. ... why these characters are now a part of Megas. ...
    (rec.arts.anime.misc)