SieRobin Posted September 5, 2006 Share Posted September 5, 2006 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? Link to comment https://forums.phpfreaks.com/topic/19829-wordwrap/ Share on other sites More sharing options...
roopurt18 Posted September 5, 2006 Share Posted September 5, 2006 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 More sharing options...
SieRobin Posted September 5, 2006 Author Share Posted September 5, 2006 Yes exactly. Link to comment https://forums.phpfreaks.com/topic/19829-wordwrap/#findComment-86760 Share on other sites More sharing options...
AndyB Posted September 5, 2006 Share Posted September 5, 2006 http://ca.php.net/manual/en/function.str-word-count.phpSee the function posted by MadCoder Link to comment https://forums.phpfreaks.com/topic/19829-wordwrap/#findComment-86771 Share on other sites More sharing options...
SieRobin Posted September 5, 2006 Author Share Posted September 5, 2006 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. Link to comment https://forums.phpfreaks.com/topic/19829-wordwrap/#findComment-86777 Share on other sites More sharing options...
AndyB Posted September 5, 2006 Share Posted September 5, 2006 "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? Link to comment https://forums.phpfreaks.com/topic/19829-wordwrap/#findComment-86788 Share on other sites More sharing options...
SieRobin Posted September 5, 2006 Author Share Posted September 5, 2006 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 More sharing options...
Barand Posted September 6, 2006 Share Posted September 6, 2006 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 More sharing options...
AdRock Posted September 6, 2006 Share Posted September 6, 2006 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 More sharing options...
redarrow Posted September 6, 2006 Share Posted September 6, 2006 Better idear have a tryMy 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] Link to comment https://forums.phpfreaks.com/topic/19829-wordwrap/#findComment-87029 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.