marcfalk Posted November 22, 2008 Share Posted November 22, 2008 Hello , I need some help. I can't figure out why this http://pastebin.com/m1b575c55 isn't working. I need to add "..." after sentences there are 50 characters long. $name is plain text and will never include URL's etc. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 22, 2008 Share Posted November 22, 2008 How about this? <? $position=50; $messageshort = $name; if (strlen($messageshort) <= $position) { echo $messageshort; } else { echo substr($messageshort, 0, $position)."..."; } ?> Quote Link to comment Share on other sites More sharing options...
marcfalk Posted November 22, 2008 Author Share Posted November 22, 2008 It just works. Thank you man, I appreciate Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 22, 2008 Share Posted November 22, 2008 Now try to find out, why the previous one was no good. Hint:line 7 Quote Link to comment Share on other sites More sharing options...
marcfalk Posted November 22, 2008 Author Share Posted November 22, 2008 Now try to find out, why the previous one was no good. Hint:line 7 hmm , if ($postshort != $position) doesn't contain $messageshort, which is quite essential since that's the text I'm trying to add "..." after? I mean, I missed an important factor in my if-statement. Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 23, 2008 Share Posted November 23, 2008 You probably wanted to check, if $postshort has 50 characters or more. Well, that's not the way to do it strlen should be used in such cases Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.