johnnyboy16 Posted September 2, 2010 Share Posted September 2, 2010 Howdy, I have a page on my site that displays events I have uploaded. Below is the code that displays the event title. I want to know if there is a simple way to limit the characters of the title that a view will see. For example, limiting the title to 10 characters. So, if I had an event titled "My awesome new event". You would see "My awesome..." Hope this makes sense. I'm not sure if you will need to see more of the code to help me, thank you! <a href ="event-description.php?eid=<?php echo $data->EventId?>"<span class="events-title"><?php echo $data->EventTitle ?> Quote Link to comment https://forums.phpfreaks.com/topic/212371-string-length/ Share on other sites More sharing options...
Alex Posted September 2, 2010 Share Posted September 2, 2010 $title = "My awesome new event"; echo substr($title, 0, 10) . "..."; substr Quote Link to comment https://forums.phpfreaks.com/topic/212371-string-length/#findComment-1106509 Share on other sites More sharing options...
fortnox007 Posted September 2, 2010 Share Posted September 2, 2010 Hope this is what you were looking for. If anyone knows a shorter or better way let us know <?php $text = "All i want to do is eat banana's and throw coconuts at fat tourists while sitting in a tree"; //condition if (strlen($text) > 10) { $tekst = substr($text, 0, 10) . ".."; //appending some dots in case string is longer echo "$text"; } else // if text isnt longer than 10 characters { echo "$text"; } ?> : Quote Link to comment https://forums.phpfreaks.com/topic/212371-string-length/#findComment-1106514 Share on other sites More sharing options...
fortnox007 Posted September 2, 2010 Share Posted September 2, 2010 lol nice one alex Quote Link to comment https://forums.phpfreaks.com/topic/212371-string-length/#findComment-1106516 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.