1. Related information
When outputting a long string in PHP (the string has no line breaks), it is hoped that the string can automatically wrap when the content exceeds the set length, otherwise the string without line breaks will Exceeding the set width, the page will be stretched infinitely
In pure HTML code, even without any special declaration, it will automatically wrap according to the set width, for example
<code><span><<span>div</span><span>style</span>=<span>"width: 100px;"</span>></span> 测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试 <span></<span>div</span>></span></code>
The above code will when the content width exceeds 100px Will automatically wrap the output
But when outputting a long string of php
<code><span><<span>div</span><span>style</span>=<span>"width: 100px;"</span>></span><span><span><?php</span><span>echo</span><span>$long_content</span>; <span>?></span></span><span></<span>div</span>></span></code>
The content width of $long_content
is far more than 100px, you can see that the content output will not automatically wrap the line, it will be based on the string The width of the page is infinitely stretched, that is, it will be stretched as long as it is. The defined width is imaginary, which is obviously not what we expect. 2. Problem description
When a long string is output, the content will not Automatic line wrapping will stretch the page infinitely
3. Solution
Use the following css definition
<code><span><<span>div</span><span>style</span>=<span>"width: 100px; word-break: break-all;word-wrap: break-word;"</span>></span><span><span><?php</span><span>echo</span><span>$long_content</span>; <span>?></span></span><span></<span>div</span>></span></code>
break-all
indicates that line breaks are allowed within words. . The
break-word
means wrapping inside long words or URL addresses.