To solve the problem of replacing line breaks with spaces, replace space with & amp; nbsp; line breaks with & lt; br & gt; doubt: replace space with & quot; whether the s line break is n or the rn environment is in a non-IR browser. Statement of solution, all replaced at one time. Set the content to $ txt ------ solution ------------------ PHPcodeechopreg_r line break space replacement problem
I want to replace spaces
Replace line breaks
Doubt:
Enter "" or \ s as a space when replacing
Whether the line break is \ n or \ r \ n
The environment is in a non-IR browser
Internet Explorer does not need to be considered.
Statement of solution, all replaced at one time.
Set content to $ txt
------ Solution --------------------
PHP code
Echo preg_replace (array ('//', '/[\ r \ n] +/'), array ('','
'), $ String );
------ Solution --------------------
$ Changeset = array ('\ r \ n' =>'
', ''=>' $ Nbsp ;');
$ Str = strtr ($ str, $ changeset );