thman_get_limited_string

Discussion in 'PHP' started by tgma, Jan 12, 2011.

  1. #1
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php echo thman_get_limited_string($post->post_title,13); ?></a>
    PHP:
    Because there isn't enough space for the whole title the title has to be cut but this code creates a second line if the last word which is allowed to be displayed is too long.

    Example 1
    Whole title: 12345 123456 12345678 12345678 1234567890
    (2 Lines)


    12345 123456
    12345678...

    Example 2
    Whole title: 123 123456 123456 12345678 1234567890
    (1 Line)


    123 123456 123456...

    Question:

    How can I change the code to insert a <br /> if I get Example 2? And if I get Example 1 then a <br /> shouldn't be inserted.
     
    tgma, Jan 12, 2011 IP
  2. Tanya Roberts

    Tanya Roberts Active Member

    Messages:
    250
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #2
    replace thman_get_limited_string($post->post_title,13); with:

    str_replace("brterm","brteeerm<br />",thman_get_limited_string($post->post_title,13));

    where brterm means the term before you break the line. ie. if the title is "my name is tanya and i am writing a post about me" then if you want a <br /> tag in front of "and" then just write the following:

    str_replace("and","and<br />",thman_get_limited_string($post->post_title,13));
     
    Tanya Roberts, Jan 13, 2011 IP