Jump to content

String Length


johnnyboy16

Recommended Posts

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 ?>

 

Link to comment
Share on other sites

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";
    }
?>

 

::) ::)::)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.