Muhammad Shahzad Muhammad Shahzad - 2 months ago 9x
PHP Question

php check string has no space and length greater than limit

I have a website where user can add reviews. Now Issue is some user add very lengthy strings and I'm unable to stop them to do that, like a user added a review:


Another user put this review:


Here is code:

if (isset($_POST['addReview'])) {
$summary = isset($_POST['summary']) ? trim($_POST['summary']) : '';

How I can check input string length and make sure there are no reviews like above and input is only words?


A better solution would be to use

word-wrap: break-word;

It will break the string when it gets too long