Jump to content


Photo

WordWrap


  • Please log in to reply
9 replies to this topic

#1 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 05 September 2006 - 10:43 PM

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?

#2 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 05 September 2006 - 10:49 PM

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 ..."
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#3 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 05 September 2006 - 10:52 PM

Yes exactly.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 September 2006 - 11:10 PM

http://ca.php.net/ma...-word-count.php

See the function posted by MadCoder
Legend has it that reading the manual never killed anyone.
My site

#5 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 05 September 2006 - 11:20 PM

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.

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 September 2006 - 11:44 PM

"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?
Legend has it that reading the manual never killed anyone.
My site

#7 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 05 September 2006 - 11:51 PM

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.

#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 06 September 2006 - 12:25 AM

Do you mean
<?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; 
?>

--> Hello, World! Today...
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#9 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 06 September 2006 - 11:46 AM

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 http://www.somesite....t/something.php it displays it as http://www.somesite.com/products/... but still has the full length url so if clicked it still works
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 06 September 2006 - 12:01 PM

Better idear have a try

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

<?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;

?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users