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. Link to comment https://forums.phpfreaks.com/topic/133756-problems-with-if-else/ 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)."..."; } ?> Link to comment https://forums.phpfreaks.com/topic/133756-problems-with-if-else/#findComment-696118 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 Link to comment https://forums.phpfreaks.com/topic/133756-problems-with-if-else/#findComment-696532 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 Link to comment https://forums.phpfreaks.com/topic/133756-problems-with-if-else/#findComment-696540 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. Link to comment https://forums.phpfreaks.com/topic/133756-problems-with-if-else/#findComment-696585 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 Link to comment https://forums.phpfreaks.com/topic/133756-problems-with-if-else/#findComment-696893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.