Jump to content

Split huge words


jaymc

Recommended Posts

Ok, I want to turn this

 

"Helooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"

 

Into something more presentable such as

 

"Helooooooooo"

 

I can do this fine in PHP, i have made the following function;

 

// STOP EXCESIVE SCROLLING
$words = explode(" ", $message);
$wordarray = array();
foreach ($words as $words) {
if(strlen($words)>50){
$words=substr($words, 0, 50);
}
$wordarray[] = $words;
}
$message = join(" ", $wordarray);

 

if you dont know php, ignore that example, if you do then you should know exactly what Im trying to do

 

 

The reason for this is if someone posts a comment and doesnt have a space in a stupid word 50 chars long, it stretches the table or div its in

 

The way around it is to identify words that are over 50 chars and cut them off at char 50, as per my example above

 

How can this be acheived in javascript?

Link to comment
https://forums.phpfreaks.com/topic/76790-split-huge-words/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.