web_master Posted January 8, 2010 Share Posted January 8, 2010 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 More sharing options...
cags Posted January 8, 2010 Share Posted January 8, 2010 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. Link to comment https://forums.phpfreaks.com/topic/187702-print-only-few-characters/#findComment-990936 Share on other sites More sharing options...
web_master Posted January 8, 2010 Author Share Posted January 8, 2010 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! Link to comment https://forums.phpfreaks.com/topic/187702-print-only-few-characters/#findComment-990958 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.