Page 1 of 1

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

Posted: Sun Dec 28, 2003 2:42 pm
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,

Posted: Sun Dec 28, 2003 3:03 pm
by microthick
To store and retrieve images from MySQL, this is the tutorial I first learned from:

http://www.phpbuilder.com/columns/florian19991014.php3

Posted: Sun Dec 28, 2003 3:20 pm
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....

Posted: Sun Dec 28, 2003 3:58 pm
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,

Posted: Sun Dec 28, 2003 4:08 pm
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?"...":"");
}

Posted: Sun Dec 28, 2003 4:52 pm
by Subliminal
Awesome Thanks!