开发者

Breaking the string in certain number of characters

I am looking for the shortest, elegant way to break the unicode string in to certain number of character.

I am having the div enter code herewith different language strings. I am breaking the string after certain number of characters. But for capital and small letters in English there was UI distortion.

I am looking for some workaround to break the string uniform way for any Unicode or capital character or numbers so UI remai开发者_如何转开发ns intact.

<html>
<head>
 <title>test </title>
<style>
  .contri-title
{
float:left;
width:625px;
background-color:#fff0f0;
}

}
</style>
 </head>
 <body>
<div class="contri-title bottom-part" id="art_title">AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</div>
<br>
<div class="contri-title bottom-part" id="art_title">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
 </body>
</html> 


If you want to do this with PHP (like it was tagged) you can use

  • wordwrap — Wraps a string to a given number of characters

Example from Manual:

$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", true);
echo "$newtext\n";

outputs

A very
long
wooooooo
ooooord.

I am not sure if this supports multibyte strings though, so you can also have a look at

  • Truncate multibyte string to n chars

and adjust the solution to your needs.


Add following property in your CSS class

word-wrap:break-word;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜