1

How can I limit the anchor text below to show only 50 characters?

echo '<td style="" class="pointlink"><span class="pointlink"><a href="http://'.$rowad["1site"].'">'.$rowad["1site"].'</a></td>'; 
1
  • 2
    substr() is the function you want Commented Sep 3, 2012 at 21:01

3 Answers 3

7

substr

Alternatively, you could use CSS:

.pointlink { width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } 

Adjust the width as needed, and an ellipsis will be automatically be used to cut off the text.

Sign up to request clarification or add additional context in comments.

7 Comments

Upvoting - because you would have ellipsis to show truncation and this can be dynamically resized based on the size of the page.
cute, but inefficient and with serous browser support issues.
Supported by all major browsers: w3schools.com/cssref/css3_pr_text-overflow.asp
here is a better one by version - IE6 supported it - how high are your standards? caniuse.com/text-overflow
well if w3schools, says so it must be true :-) but my phone browser does not support it :(
|
3

You can use the substr function to cut the text down to 50 characters

function cut_text( $text, $len ) { return strlen( $text ) > $len ? substr( $text, 0, $len ) + '...' : $text; } echo '<td style="" class="pointlink"><span class="pointlink"><a href="http://'.$rowad["1site"].'">' . cut_text( $rowad["1site"], 50 ) . '</a></td>'; 

1 Comment

Nice - but you should use '&hellip;' to get a real one '…' instead of '...' - the point is to save space after all :-) (LOL - that looks a lot bigger in the edit box...)
2

You can use substr function, like

echo '<td style="" class="pointlink"><span class="pointlink"><a href="http://'.$rowad["1site"].'">'.substr($rowad["1site"],0,50).'</a></td>';

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.