html - php: how to split up a really long string -
this question has answer here:
i new php , have question.
i've made chat-like application, working can't seem find want in searching previous threads.
the user can input form field $message. so...
$message = $_post['message'];
the input box allows maximum of 600 characters. if user posts nothing 1 long entire string doesn't contain white space, or spaces between of string characters.. short example..
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
if goes length, causes page break creating horizontal scroll frame.
how can take $message , filter break up? taking account users posting real $message, , not accidentally split valid words etc. maybe checks see if 1 of $message array elements longer xxx amount of characters long , if break up? or what's easiest way go this?
you should put content of $message
inside element
class
set break long lines (word-wrap: break-word):
i.e:
.php
<?php if(isset($message = _$post['message'])){ $message = _$post['message']; echo "<div class='message'>$message</div> }
.css
.message { word-wrap: break-word; /* careful this, breaks normal words */ word-break: break-all; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; }
the above works in internet explorer 8+, firefox 6+, ios 4.2, safari 5.1+ , chrome 13+.
Comments
Post a Comment