A
A
Alexander2010-10-08 14:30:14
PHP
Alexander, 2010-10-08 14:30:14

How to remove empty line breaks in html page code

Help solve the problem. I process the text in php using strip_tags(), then I cut /n /t /r using str_replace() but the text looks like this

The practice of using offshore companies in the world.
In the program:

Offshore, low-tax and prestigious European juris

How to get rid of these transitions so that the text looks like a single line in the page code?

The practice of using offshore companies in the world. In the program: Offshore, low-tax and prestigious European jurisprudence

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vladimir Chernyshev, 2010-10-08
@zlobin

$text = str_replace(array("\n", "\r"), '', $text);
works for me

O
ojiga, 2010-10-08
@ojiga

$text = str_replace("\n",'',$text);
write double quotes

S
Sererator, 2010-10-08
@Serator

There are simply no words ...
In general, first set the task for the future, and then solve it. Judging from the explanation, you do not need to remove "\n" and "\r", but replace any of their sequence with 1 space (most likely exceptions are possible, but only you know them). So, if any empty characters can fall under this, then you can write:
$text=preg_replace('/\s+/',' ',$text);# Replace all sequences of empty characters with 1 space
Or the same with enumeration in an array through str_replace (I would stop at the regular expression).
This code will replace any sequence of characters included in "\s" with 1 space.
And read the php help, because there it is written about the difference in " and ', and about the functions used in the example,

A
Alexander, 2010-10-08
@zlobin

in short it looks like this
$text = strip_tags($row['text'],'');
$text = str_replace('\n','',$text);

A
abrwalk, 2010-10-08
@abrwalk

Special characters are not processed in single quotes, '\n' will not look for a newline, but string two characters \n.
accordingly to change

qwe
asd

on the
qwe
asd

you need to look for "\n\n" and replace with "\n"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question