Forum Moderators: coopster

Message Too Old, No Replies

Using substr() without breaking a word

Here is a good solution

         

henry0

9:08 pm on Jan 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I feel I owe you:
I remember a while ago we had a few threads about
showing partial result from a query without cuting in the middle of a word.

We know that using substr()directly in PHP
or in a MySQL query ,SUBSTRING('my_var', 0,100) as 'text', etc.. will result in word breaking

While I was searching the manual I found a user ()
that does a perfect job
so visit it HERE [us2.php.net]
scroll down to the 3rd post and look for strtrim()
a well done demo and useful :)

jatar_k

9:10 pm on Jan 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I always just used substr and then got rid of everything after the last space in the string

eelixduppy

9:12 pm on Jan 3, 2007 (gmt 0)



Here it is! How to avoid words being chopped with SUBSTR
[webmasterworld.com]

...for those interested in other solutions, similar to jatar's :)

[edited by: eelixduppy at 9:37 pm (utc) on Jan. 3, 2007]

henry0

9:15 pm on Jan 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jatar_k: So simple and efficient!

jatar_k

10:01 pm on Jan 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> Apr 12, 2004

hehe, nice eelix

makes me think of old dogs and new tricks ;)