W
W
wartur2012-01-28 00:33:49
PHP
wartur, 2012-01-28 00:33:49

PHP mb_ereg_replace - I have to turn to Habr, I don't understand the problem?

Hello.
I've run into a problem that I don't understand. I need to write data from a textarea to the database with a line break [br], I can't. I tried a lot of ways including multibytes, although they should not be connected in any way here.
$message sink:

Это мой уникальный контент,\r\nЭто перенос строки,\r\nА это запрос к БД \' OR \'

Should be converted to
Это мой уникальный контент,[br]Это перенос строки,[br]А это запрос к БД \' OR \'

Tried the following ways, I list them all.
// самый совершенный вариант относительно UDF-8
$text = mb_ereg_replace("\r\n|\r|\n", "[br]", $message);

// Из документации PHP
$order   = array("\r\n", "\n", "\r");
$replace = '[br]';
$text = str_replace($order, $replace, $message);

// Теоретически самый правильный вариант
$text = nl2br ($message);

// Другие варианты со стек оверфлова заключающиеся в реализации mb_str_replace

Windows platform
XAMPP
PHP 5.3.8
All work in UTF-8 from HTML to PHP.
What am I doing wrong? I have the same line in $text. Is it supposed to be like this or am I a failure?
PS: it works flawlessly! I've run out of options. I do not know what to do. PS2: Something happened with the backlight on Habré. All [br] should be considered as a <..> tag, because naturally I will write statics in the database, but this is not the point.
$text = mb_ereg_replace("мой", "[br]", $message);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iStyx, 2012-01-28
@wartur

And in the text you have exactly \r\n, and not the slash_symbol+r(n)?

W
wartur, 2012-01-28
@wartur

Sorry, problem solved. For those who suddenly stumbled.
Up to this point, with the $message line, I mocked this mysql_real_escape_string function - it replaces all special characters, including line breaks. Therefore, it is impossible to find them later. We need to look for them as \\r and \\n.
The problem is that I really screwed up with the fact that XDEBUG still showed \r\n and they were already there as characters, and not as special characters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question