- Forums
- PHP
- Limit The Number Of Characters In A String Variable
use this howto tutorial will show you how you can limit the number of characters in a string to be displayed [1301], Last Updated: Sat May 18, 2024
wallpaperama
Fri Sep 09, 2011
0 Comments
427 Visits
today we received a question we often get regarding creating code for a wallpaper website using PHP. this is the question
question: i am doing some work for a wallpaper website and i need to display some text into a form but some of these field values are too long, i want to limit the value of a string to only a certain amount of character
answer: you can use the substr() in PHP to limit the amount of characters is displayed on your webpage.
example, $foo is 500 characters long, i want to show only the first 30 letters:
<?php
$foo = 'Wallpaperama is a great source for help on your wallpaper website';
$foo = substr($foo, 0,30);
echo $foo;
?>OUTPUT:
Wallpaperama is a great source
hope that helps anyone