trim, cut, shorten text - also storing images in sql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

trim, cut, shorten text - also storing images in sql

Post by Subliminal »

Hi Guys,

Could someone please point me in the direction of a good SIMPLE example of how to store and pull images from MySQL?

Also what is the PHP function to trim text. What I would like to do is set a character length of lets say 10 and then put "..." on the end of the text. Of course the text is pulled from MySQL as well. I have checked the PHP manual and with "trim" it seems like you can only trim certain characters.

Thanks as always,
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

To store and retrieve images from MySQL, this is the tutorial I first learned from:

http://www.phpbuilder.com/columns/florian19991014.php3
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

umm.. store the ACTUAL image or it's location?????

i ask becasue if you store the actual image then you're using sql as a file table.. you already haveone in the operating system and it would be much faster to use the operating system than to do that in sql....
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

Post by Subliminal »

Hem I never thought of using the OS' filesystem. Thanks for the tip. Oh and the link to storing in MySQL i guess I will give both a shot.

Any word on trimming text?

Thanks,
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

If you're going to retrive that text from mysql you can use something like this:

Code: Select all

select concat(left(field,10),if(length(field)>10,'...','')) as field .....
or if you're talking about pure php then:

Code: Select all

function trim_text($text){
  return substr($text,0,10).(strlen($text)>10?"...":"");
}
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

Post by Subliminal »

Awesome Thanks!
Post Reply