Answer the question
In order to leave comments, you need to log in
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 \'
Это мой уникальный контент,[br]Это перенос строки,[br]А это запрос к БД \' OR \'
// самый совершенный вариант относительно 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
$text = mb_ereg_replace("мой", "[br]", $message);
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question