Jump to content

print only few characters


web_master

Recommended Posts

Hi,

 

when I reload text from database I want to print only a few characters of each text, so I dont know how can I do that?

 

For example the text in database is: The quick brown fox jumped over the lazy dogs

But I  want to print only like this: The quick brown fox ...

 

Thankx in advanced,

 

T

Link to comment
https://forums.phpfreaks.com/topic/187702-print-only-few-characters/
Share on other sites

There are lots of ways of doing it, if you want a certain number of characters you can simply use a function such as substr to fetch the start of the string (in fact you could even use MySQL's built in substr function if you wanted). If you want a certain number of words or if you wanted a certain number of words you could use explode to get the words then implode the first x amount to get your string. Another way of doing it would be to use Regular Expressions. You could in theory match x amount of characters but round up to the end of a word. It all depends exactly what your looking for.

There are lots of ways of doing it, if you want a certain number of characters you can simply use a function such as substr to fetch the start of the string (in fact you could even use MySQL's built in substr function if you wanted). If you want a certain number of words or if you wanted a certain number of words you could use explode to get the words then implode the first x amount to get your string. Another way of doing it would be to use Regular Expressions. You could in theory match x amount of characters but round up to the end of a word. It all depends exactly what your looking for.

 

Thank You, its work!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.