PHP Code How To Display Only A Certain Amount of Characters Limit Letters
RegisterLogin
PHP Code How To Display Only A Certain Amount of Characters Limit Letters
Post Description: PHP Code How To Display Only A Certain Amount of Characters Limit Letters
Tags: PHP, Code, How, To, Display, Only, A, Certain, Amount, of, Characters, Limit, Letters
This Post Was Posted On Feb 29, 2008 By web hosting #1219
Post Description: PHP Code How To Display Only A Certain Amount of Characters Limit Letters
Tags: PHP, Code, How, To, Display, Only, A, Certain, Amount, of, Characters, Limit, Letters
This Post Was Posted On Feb 29, 2008 By web hosting #1219
PHP Code How To Display Only A Certain Amount of Characters Limit Letters by web hosting
so lets say i have a long string, but when i want to show it on my website it doesnt' fit because the string has too many characters or letters or words and i only want to show only a limited about of words. so lets say my string is called $string and this is the value of $string
Code:
I am writing this tutorial to show you how you can cut down on the words with php. if you need php web hosting, our friends at webune.com have the right solution for you. dedicated hosting is the best way to go if you have a large website. as you can see, this string is pretty long.
if you count the number of character in the paragraph above you can see i have 283 character, so lets say i only want to display 100 this is the code i would use:
Code:
<?
$string ="I am writing this tutorial to show you how you can cut down on the words with php. if you need php web hosting, our friends at webune.com have the right solution for you. dedicated hosting is the best way to go if you have a large website. as you can see, this string is pretty long.";
echo substr($string, 0,100);
?>
$string ="I am writing this tutorial to show you how you can cut down on the words with php. if you need php web hosting, our friends at webune.com have the right solution for you. dedicated hosting is the best way to go if you have a large website. as you can see, this string is pretty long.";
echo substr($string, 0,100);
?>
this will be the output:
Code:
I am writing this tutorial to show you how you can cut down on the words with php. if you need php w
i wrote up an example script you can use so that you can see it in action. just remember, you must have PHP on your web site. if you don't have PHP, you can visit our friends at www.webune.com and signup with the with PHP hosting.
copy and paste the following code into notepad and save it as remove-chars.php then upload to your site and open it with you browser to see how it works:
Code:
<?
echo "<h1>I will limit 100 character in a string</h1><hr>";
$string ="I am writing this tutorial to show you how you can cut down on the words with php. if you need php web hosting, our friends at webune.com have the right solution for you. dedicated hosting is the best way to go if you have a large website. as you can see, this string is pretty long.";
echo "this is <b>$string</b> before substr() function: $string <BR><BR>";
echo "this is how many character i have in <b>$string:</b> <br><b>".strlen($string)."</b><BR><BR>";
$string = substr($string, 0,100);
echo "this is <b>$string</b> after substr() function: <br><b>$string</b>";
?>
<p> </p>
<p>Dont forget to tell your friends about where they can find free amazing wallpapers, only at Wallpaperama!</p>
<p align="center">Script by <a href="http://www.wallpaperama.com">wallpaperama.com</a> </p>
<p align="center">PHP Hosting at <a href="http://www.webune.com">Webune.com </a></p>
echo "<h1>I will limit 100 character in a string</h1><hr>";
$string ="I am writing this tutorial to show you how you can cut down on the words with php. if you need php web hosting, our friends at webune.com have the right solution for you. dedicated hosting is the best way to go if you have a large website. as you can see, this string is pretty long.";
echo "this is <b>$string</b> before substr() function: $string <BR><BR>";
echo "this is how many character i have in <b>$string:</b> <br><b>".strlen($string)."</b><BR><BR>";
$string = substr($string, 0,100);
echo "this is <b>$string</b> after substr() function: <br><b>$string</b>";
?>
<p> </p>
<p>Dont forget to tell your friends about where they can find free amazing wallpapers, only at Wallpaperama!</p>
<p align="center">Script by <a href="http://www.wallpaperama.com">wallpaperama.com</a> </p>
<p align="center">PHP Hosting at <a href="http://www.webune.com">Webune.com </a></p>
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
webune
#4464 1
i want this code:
<?php
$foo = 'hello"; // has 5 characters
if($foo > 2){
echo 'has more than 2 characters';
}else{
echo 'has less than 2 characters';
}
what can i use?
ok, this is simple. just use the str_len() function
<?php
$foo = 'hello"; // has 5 characters
if($foo > 2){
echo 'has more than 2 characters';
}else{
echo 'has less than 2 characters';
}
what can i use?
ok, this is simple. just use the str_len() function
Sep 20, 2010 Reply Report abuse
eca
#1657 2
this is a good code of php only show so many words in a string. i tried it myself and it works, thants for writing this simple to use tutorial guide.
Feb 08, 2007 Reply Report abuse
©2011 Webune Forums - Sun Dec 18, 2011 8:44 pm
Powered by: Webune Forums V3
Powered by: Webune Forums V3