Welcome to WebmasterWorld Guest from 54.167.0.111

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

server-side maximum character limit for textarea?

     

ewwatson

5:01 pm on Apr 4, 2008 (gmt 0)

5+ Year Member



Hello everyone, I found a few methods but this stuff is still somewhat greek to me, so which do you guys prefer? Thanks!

$clipped_string=substr($_POST['textarea'],0,512);

or

<?
$position=14; // Define how many character you want to display.
$message="You are now joining over 2000 current";
$post = substr($message, 0, $position);
echo $post;
echo "...";
?>

or

$charLimit = 500;
if (strlen($_POST['desc']) <= $charLimit)
{
// do something
} else {
// do error
}

or

<?php
if (strlen($_POST['input']) > 300) {
// appropriate rejecting mechanism
} else {
// do what you want with it.
}
?>

MRaja

5:16 pm on Apr 4, 2008 (gmt 0)

5+ Year Member



Better to tell us what is the issue that you want to solve with this methods. the first, second, third & forth are good , every one for specific needs.

ewwatson

6:02 pm on Apr 4, 2008 (gmt 0)

5+ Year Member



Hello, I want to set a maximum amount of characters in my textarea on the server side. I already have this set on the client side. So I am just looking for the best method to add to my pre-existing formmail.php. Thanks!

coopster

6:25 pm on Apr 5, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



It depends on whether or not you want to clip the text at the last character in the middle of a word or not. If you don't care, then using substr [php.net] will be fine. If you want to make sure you don't clip a word you could use wordwrap [php.net].
 

Featured Threads

Hot Threads This Week

Hot Threads This Month