Jump to content

Archived

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

SieRobin

WordWrap

Recommended Posts

K, so basically all I want to do is that when it gets to the end of the wrap, just to output "..." instead of just doing a line break and continuing the rest of the text. Is there a way to do that?

Share this post


Link to post
Share on other sites
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 ..."

Share this post


Link to post
Share on other sites
http://ca.php.net/manual/en/function.str-word-count.php

See the function posted by MadCoder

Share this post


Link to post
Share on other sites
I see, it works fine but the only problem I have with it is, if it doesn't word wrap, then it just puts the "..." in there anyhow, for no apparent reason lol.

Share this post


Link to post
Share on other sites
"Doesn't word wrap"?

Do you mean when the strings of words is long enough to wrap around to a new line, or do you mean when the string is too short that the n words you want to display is as long or longer than the string?

Share this post


Link to post
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.

Share this post


Link to post
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...

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Better idear have a try

My example wont effect the table and can use any size url.

[code]
<?php

$bussiness_name="members bussiness name for this link";

$url="http://www.google.com";

$url=str_replace($url,"<a href='$url'>$bussiness_name</a>",$url);

echo $url;

?>

[/code]

Share this post


Link to post
Share on other sites

×

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.