How do I cut a string by a particular number? I know how to measure the length of string using strlen function.
For instance: from a text area form field, I would like to limit my visitors so they can have for 50 characters only. How do I do that?
substr()
I think using javascript to detect the lenght of the string before it is submitted would be much more user friendly than having them submit with what they think will work, only for them to find out that it has been cut off at 50.
🙂
I would also suggest putting a limit in the actual text box.
<input type="text" size="50" maxlength="50" name="whatever">
well, I do agree that cutting off some string without user knowledge is not a good idea. That, of course should only be done when user tries to violate the MAXLENGTH you've set (by saving and changing the form locally). 😉
Thank you, scoppc for substr
Off course I'll tell the visitor before, before I cut their input.