I use nl2br to convert nl characters to a tag, but for ex I want to convert "Hello \ n \ n \ n \ n Everybody" to "HelloEverybody", also I want to convert multinewlines to one br tag. How can i do this?
The most direct approach may be to first replace multiple lines of a newline with one using a simple regular expression:
nl2br(preg_replace("/\n+/", "\n", $input));
If you have php 5.2.4+ you can use preg_replace and the character type of the vertical space \v
\v
$str = preg_replace('/\v+/','<br>', $str);
preg_replace(), nl2br HTML. nl2br(preg_replace('/\n+/', '\n', $the_string)) ().
nl2br(preg_replace('/\n+/', '\n', $the_string))
Source: https://habr.com/ru/post/1717031/More articles:Is there a way to get the curried form of binary operators in SML / NJ? - operatorsBest way to unleash (for parallel processing) a web application without immediate processes? - c #Can I encode spaces as% 20 in POST from WWW :: Mechanize? - httpLine Sensitivity - c #generally detect html position changes using jquery? - domCode Editor for C # Code - c #When should new .NET projects be created for the .NET 4 Framework - ruby-on-railsHelp interpret gdb: segfault in function - cSQL error logging - sql-serverDjango preview, TypeError: 'str' object cannot be called - djangoAll Articles