jaymc Posted November 10, 2007 Share Posted November 10, 2007 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? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted November 12, 2007 Share Posted November 12, 2007 the javascript version of explode() is split() and it allows regular expresions too: http://www.w3schools.com/jsref/jsref_split.asp Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.