Page 1 of 1
problems re displaying blobs
Posted: Mon Jun 06, 2005 11:13 pm
by adster
Hi Guys,
I have a blob in my db and i would like to be able to display say the first 50 words from the blob.
Displaying the entire blob is no problem, i just can't seem to figure out how to display a summary of it.
any help would be greatly appreciated.
cheers,
Adam
Posted: Tue Jun 07, 2005 9:01 am
by artexercise
one method would be to explode the blob into an array using the " " space as a delimiter. Then displaying the first 50 elements of the array.
Another method would probably involve regular expressions which I am far from an expert on.
Posted: Tue Jun 07, 2005 9:24 am
by John Cartwright
Code: Select all
preg_match('#^\s*(.{60,}?)\s+.*$#s',$row['data'],$matches);
I think you should grab the first # of characters instead of words so you can more easily control the total length. This snipplet will grab the first 60 characters, and not cut off any words.
I'm not a guru in mysql, but you could try doing this
Code: Select all
$sql = "e;SELECT SUBSTRING(0,60,`columname`) FROM `data`"e;;
Not sure if that would work, and it also will cut off words. I recommend using regex.
Posted: Tue Jun 07, 2005 12:38 pm
by adster
Hi JCart,
Thanks for the reply.
When i use your php code snippet
$comment = preg_match('#^\s*(.{100,}?)\s+.*$#s',$row['comment']);
I get ´1´ as my output when i echo my variable $comment.
any ideas on what i might be doing wrong?
cheers,
Adam
Posted: Tue Jun 07, 2005 1:28 pm
by Burrito
try:
Code: Select all
preg_match('#(^\s*(.{60,}?)\s+.*$)#s',$row['data'],$matches);
echo $matches[1];
edit: err maybe matches[2];
Posted: Tue Jun 07, 2005 8:51 pm
by adster
Burrito,
Thanks very much. All solved, now i think it's time to learn all about regex. argh
thanks to all for the help, very much appreciated. Now i can complete my i hate russell crowe page
cheers,
Adam
Posted: Tue Jun 07, 2005 9:35 pm
by Skara
Now i can complete my i hate russell crowe page
well thank god for that!

Posted: Tue Jun 07, 2005 10:00 pm
by Burrito
adster wrote:
Thanks very much. All solved, now i think it's time to learn all about regex. argh
d11 wrote a fantastic tutorial on regex
here