Jump to content

WordWrap


SieRobin

Recommended Posts

Are you saying that you want to display text, however once the text reaches a certain length to stop outputting that text and include elipses instead?

For example, the text "Hello, World!  Today I went shopping." would be displayed as "Hello, World! Today ..."
Link to comment
https://forums.phpfreaks.com/topic/19829-wordwrap/#findComment-86759
Share on other sites

Right the number I set is when it's adjusted to wrap the words, correct? Well the way it's set up is with an if else statement, but the else continuously kicks in, the if statement is pretty much useless.

If you actually look at the script, you'll see where it basically says, if the text exceeds the count forget everything thereafter and input "..." else output nothing. Doesn't work.
Link to comment
https://forums.phpfreaks.com/topic/19829-wordwrap/#findComment-86793
Share on other sites

Do you mean
[code]<?php
$max = 20;
$txt = "Hello, World! Today I went shopping.";
if (strlen($txt) > $max) {
    list ($firstline) = explode('|', wordwrap($txt, $max, '|'));
    echo $firstline . '...';
}
else echo $txt;
?>[/code]

--> Hello, World! Today...
Link to comment
https://forums.phpfreaks.com/topic/19829-wordwrap/#findComment-86806
Share on other sites

Is it possible to use the above example to do this?

I have urls stored in a database and I echo them in a table column but some urls are so long it makes the other 2 columns really short.  I would like to use the above example to shorten the length of the outputted url so instead of having something like [url=http://www.somesite.com/products/something/this/that/something.php]http://www.somesite.com/products/something/this/that/something.php[/url] it displays it as [url=http://www.somesite.com/products/...]http://www.somesite.com/products/...[/url] but still has the full length url so if clicked it still works
Link to comment
https://forums.phpfreaks.com/topic/19829-wordwrap/#findComment-87024
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.