• Web 2.0 platform and Programming Language

    We are promoting Web 2.0 platform in our template design, xHTML in our scripting and PHP programming language in our server side programming. So try our services and be satisfied with the outcome.

  • HTML/xHTML Standard

    This site passed and uses the W3C XHTML 1.0 Transitional standard, CSS level 2.1 driven, Javascript and with a latest trend of Table-less xHTML scripting by not using <table> tag in making our script.

  • Website History

    This website was founded last October 18, 2007, fully bought the domain February 2008 and has been continually updating. We are located at heart of The City of Golden Friendship Cagayan de Oro the City.

PHP Function to Limit String output or display

This is a PHP Function thats limits string output or display. This is useful when you have an article and you want to show the first 200 characters of that article in order for you to show only full characters when users browse the whole or specific article.

While many function of this kind are already made, this function is a little bit different because it is cocern on displaying string that is W3C standards. To explain it, this function converts special characters to html entities and also remove tags on your string so that the script could count the characters accurately. Just read/run the code and you will see what I mean.

Please fell free to comment and improve this function. Thanks…!

function limit_chars( $string, $lenght=50, $allowable_tags='', $char_set='ISO-8859-1', $dots='...'){

	if($allowable_tags != ''){
		$char_set = strtoupper($char_set);

		$string = strip_tags($string,$allowable_tags);
		$string = html_entity_decode($string,ENT_QUOTES,$char_set);

		$strlength = strlen($string);

		if ( $strlength > $lenght ){
			$limited = substr($string, 0, $lenght);
			$limited .= $dots;
		} else {
			$limited = $string;
		}

		$limited = htmlentities($limited,ENT_QUOTES,$char_set);
	} else {

		$strlength = strlen($string);

		if ( $strlength > $lenght ){
			$limited = substr($string, 0, $lenght);
			$limited .= $dots;
		} else {
			$limited = $string;
		}
	}

	return $limited;
}
Back to list 15 Comments Jan 19, 11 at 09:39 am

15 Responses to PHP Function to Limit String output or display

  1. Asian Tiger Mosquito says:

    2011…

    Good write-up, I’m regular visitor of one’s web site, maintain up the nice operate, and It is going to be a regular visitor for a long time….

  2. Asian Tiger Mosquito says:

    2011…

    I would like to thnkx for the efforts you’ve put in writing this website. I am hoping the same high-grade web site post from you in the upcoming as well. In fact your creative writing skills has encouraged me to get my own site now. Actually the blogg…

  3. Asian Tiger Mosquito says:

    2011…

    It is appropriate time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I want to suggest you some interesting things or advice. Maybe you could write next articles referring to this article. I want to r…

  4. Watch 11-11-11 Online says:

    2011…

    I like the valuable info you provide in your articles. I will bookmark your blog and check again here frequently. I’m quite certain I’ll learn many new stuff right here! Good luck for the next!…

  5. Asian Tiger Mosquito says:

    2011…

    Fantastic goods from you, man. I have understand your stuff previous to and you’re just extremely magnificent. I actually like what you’ve acquired here, really like what you are saying and the way in which you say it. You make it entertaining and yo…

  6. Accounting Basics says:

    2011…

    Great post. I was checking continuously this blog and I’m impressed! Extremely useful information specifically the last part :) I care for such information much. I was looking for this certain info for a very long time. Thank you and best of luck….

  7. seattle organic seo says:

    2011…

    Hi, I think your site might be having browser compatibility issues. When I look at your website in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, fantas…

  8. Accounting Basics says:

    2011…

    I’ve recently started a website, the info you provide on this site has helped me greatly. Thanks for all of your time & work….

  9. Sifisdndsk says:

    2011…

    Generally I don’t read article on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, very nice article….

  10. Accounting Basics says:

    2011…

    Having read this I thought it was very informative. I appreciate you taking the time and effort to put this article together. I once again find myself spending way to much time both reading and commenting. But so what, it was still worth it!…

  11. Accounting Basics says:

    2011…

    Hello there, You’ve done an excellent job. I will definitely digg it and personally recommend to my friends. I’m sure they’ll be benefited from this site….

  12. Accounting Basics says:

    2011…

    I’ve been exploring for a bit for any high-quality articles or blog posts on this kind of area . Exploring in Yahoo I at last stumbled upon this web site. Reading this information So i am happy to convey that I’ve an incredibly good uncanny feeling I …

  13. Asian Tiger Mosquito says:

    2011…

    Magnificent site. Plenty of useful info here. I’m sending it to some friends ans also sharing in delicious. And naturally, thanks for your sweat!…

  14. Accounting Basics says:

    2011…

    Hey, you used to write great, but the last several posts have been kinda boring… I miss your great writings. Past several posts are just a little bit out of track! come on!…

  15. Accounting Basics says:

    2011…

    Usually I don’t read article on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, very nice post….

Leave a Reply

Your email address will not be published. Required fields are marked *

*

six − = 1

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

My Blogs

  • Configuring CodeIgniter for website with HTTPS protocol view more...
    Posted: Jan 05, 12 at 11:27 am
  • Keyword “Cagayan de Oro PHP Programmer” iWebProvider.com is Number 1 at Google Search view more...
    Posted: Feb 15, 11 at 05:54 pm
  • PHP get root URL and root Directory path view more...
    Posted: Feb 15, 11 at 02:47 am
  • PHP Object Oriented Programming (OOP) using Model View Controller (MVC) approach view more...
    Posted: Feb 12, 11 at 01:56 pm
  • Launching of the new 2011 iWebProvider.com Template Design view more...
    Posted: Feb 03, 11 at 08:17 pm

Most Popular Blogs

  • Search Engine Friendly URL to convert .php and replace with .html file extension using .htaccess view more...
    Posted: Jan 19, 11 at 09:44 am
  • PHP Class for sending Email and preventing Email Spam view more...
    Posted: Jan 19, 11 at 09:41 am
  • PHP Function to Limit String output or display view more...
    Posted: Jan 19, 11 at 09:39 am
  • PHP get root URL and root Directory path view more...
    Posted: Feb 15, 11 at 02:47 am

Wise Words

"Hard work surpasses genius"

by: Mark

"It’s not about how many you have learned but how much you have utilized and mastered what you have learned."

by: Mark

"The function of good software is to make the complex appear to be simple."

by: Grady Booch

Latest Comments

My opinion is ...... Lovely just what I was searching for....

by: how to make homebrew

...... this web site is my inspiration , very superb style and perfect content ....

by: cure panic attacks

another title... I saw this really great post today....

by: print to fax

Keep in Touch

If you would like to find out more about us, just email us at inquiry[AT]iwebprovider.com