Quick Search:
Oracle PL/SQL Code Library
Find Or Post Oracle Jobs
Oracle Discussion & Chat
 PHP Code: Neatly trim a string to a set number of words Jump to:  
Category: >> PHP Code >> Neatly trim a string to a set number of words Bookmark and Share

<< lastnext >>

Snippet Name: Neatly trim a string to a set number of words

Description: Trim a string along a word boundary that you specify, and add '...' to the end.

Also see:
» Format money as millions, billions, et...
» Truncate text while preserving HTML ta...
» Neatly trim a string to a set number o...
» Convert UK Dates To mySQL Format Dates
» Search array elements for a substring
» Add a period at the end of a string if...
» Count capital letters in a string
» Search All Words Of A String In mySQL
» Remove Extra Spaces From A String
» Calculate the difference between two t...
» Get Query String with Javascript
» RMAN: Format Directives
» USER - connection information
» USER - User Information 2
» USER Information
» SQL*Plus formatting
» Create string by formatting an amount ...
» Search PL/SQL for a string/ key value
» INSTR (InString)
» SUBSTR (SubString)
» Generate unique strings of random numb...
» Count words or terms
» String Functions: REVERSE
» String Functions: LENGTH
» String Functions: INSTR
» String Functions: CONCAT
» String Functions: CHAR
» String Functions: INITCAP
» String Functions: LOWER
» String Functions: UPPER

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: May 27th, 2010

// Limit a string to a specified number of words and add '...' to end
FUNCTION neat_trim($str, $n, $delim='...') {	
	$len = STRLEN($str);
	IF ($len > $n) {
		PREG_MATCH('/(.{' . $n . '}.*?)\b/', $str, $matches);
		RETURN RTRIM($matches[1]) . $delim;
		RETURN $str;

Oracle Magazine
and Oracle White Papers

SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 33 users online    © 2009 psoug.org

Forgot your password?