Linked Questions
27 questions linked to/from Truncate a multibyte String to n chars
15 votes
9 answers
42k views
Trim text to 340 chars [duplicate]
I'm pulling blog posts from a DB. I want to trim the text to a max length of 340 characters. If the blog post is over 340 characters I want to trim the text to the last full word and add '...' on ...
9 votes
1 answer
5k views
Cutting a string with accents [duplicate]
Possible Duplicate: Truncate a multibyte String to n chars Hello, I'm developing a site in French and I created a function that cuts string after X number of characters. It works great, but when ...
1 vote
1 answer
2k views
Implement Dots After a Certain Limit [duplicate]
Possible Duplicate: Truncate a multibyte String to n chars Hye guys, So here's what I need to do. I want dots to appears after a sentence crosses a certain number of words in PHP. Ex - This is a ...
0 votes
2 answers
1k views
How to wrap words in output in PHP? [duplicate]
I want to print specific word character in specific Line (do something like a word wrap) Suppose I have 40 Character. My Name Is Johnty and i am eating an Nut and my length for character is 20. So ...
0 votes
2 answers
374 views
how to truncate a whole word? [duplicate]
Possible Duplicates: Truncate a multibyte String to n chars How to Truncate a string in PHP to the word closest to a certain number of characters? eg: PHP is a widely-used general-purpose ...
0 votes
2 answers
182 views
How to limit string output length in PHP DOM [duplicate]
I have this code for parsing RSS to HTML. <?php $channel_desc = $channel->getElementsByTagName('description') ->item(0) ->childNodes ...
-1 votes
2 answers
71 views
Trim a content from database? [duplicate]
I am calling all names from a mysql database using php. Some names are very large. so i want to show first 7 charectors and put "..." Here is my code: <?php $result = mysql_query("SELECT * FROM ...
-5 votes
1 answer
48 views
How to return the beginning of a string in php? [duplicate]
I have the following code: <!DOCTYPE html> <html> <head> <title>E6 L7</title> <meta charset="utf-8"> </head> <body> ...
393 votes
21 answers
553k views
Truncate a string to first n characters of a string and add three dots if any characters are removed
How can I get the first n characters of a string in PHP? What's the fastest way to trim a string to a specific number of characters, and append '...' if needed?
205 votes
28 answers
212k views
How to Truncate a string in PHP to the word closest to a certain number of characters?
I have a code snippet written in PHP that pulls a block of text from a database and sends it out to a widget on a webpage. The original block of text can be a lengthy article or a short sentence or ...
112 votes
6 answers
228k views
How do you pull first 100 characters of a string in PHP
I am looking for a way to pull the first 100 characters from a string variable to put in another variable for printing. Is there a function that can do this easily? For example: $string1 = "I am ...
68 votes
11 answers
101k views
Making sure PHP substr finishes on a word not a character
I know how to use the substr function but this will happy end a string halfway through a word. I want the string to end at the end of a word how would I go about doing this? Would it involve regular ...
14 votes
13 answers
19k views
How to get first x chars from a string, without cutting off the last word?
I have the following string in a variable. Stack Overflow is as frictionless and painless to use as we could make it. I want to fetch first 28 characters from the above line, so normally if I use ...
24 votes
3 answers
131k views
Truncating Text in PHP? [closed]
I'm trying to truncate some text in PHP and have stumbled across this method (http://theodin.co.uk/blog/development/truncate-text-in-php-the-easy-way.html), which judging by the comments seems like a ...
13 votes
9 answers
35k views
PHP - get first two sentences of a text?
My variable $content contains my text. I want to create an excerpt from $content and display the first sentence and if the sentence is shorter than 15 characters, I would like to display the second ...