p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: String question..HELP!


Message #1 by "kyle ketterer" <bige88fan@a...> on Sat, 20 Apr 2002 17:25:05
Hi. I have a question. Lets say I was pulling info from a DB. And I want 
to display the info as a hyperlink in a table. I want to have it so that, 
if the character length in the string is too long for the table, I want to 
cut the overlapping text off, and end the string with five of 
these ".....". Ok, here is a better visual

Lets say this is the string:
$string = "This is the string";

And this is the string "overlapped" in the table:
------------|
|This is the|
|string     |
|           |
|           |
|___________| 


I want it to look like this instead when displayed:
------------|
|This is ...|
|           |
|           |
|           |
|___________| 

Hopefully you know what I am talking about. Any help? Thanks alot, 

-kyle. 
Message #2 by Joel Silva <joelms2001@y...> on Sat, 20 Apr 2002 19:26:41 +0100
--=====================_6101092==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

Hello,

here is an idea. Hope it helps.

<?php
$string = "This is the string";

$length = strlen($string);  //returns the length of the string

$sizeOfColum = 10;  // dummy value. Use the width of the colum.
if ($length > $sizeOfColum){
         $stringToPrint = substr($string, 0, 6); // info on substr() 
available 
at 
//http://www.php.net/manual/en/function.substr 
// .php
         echo $stringToPrint.".....";
}
?>

Joel

At 17:25 20-04-2002 +0000, you wrote:
>Hi. I have a question. Lets say I was pulling info from a DB. And I want
>to display the info as a hyperlink in a table. I want to have it so that,
>if the character length in the string is too long for the table, I want to
>cut the overlapping text off, and end the string with five of
>these ".....". Ok, here is a better visual
>
>Lets say this is the string:
>$string = "This is the string";
>
>And this is the string "overlapped" in the table:
>------------|
>|This is the|
>|string     |
>|           |
>|           |
>|___________|
>
>
>I want it to look like this instead when displayed:
>------------|
>|This is ...|
>|           |
>|           |
>|           |
>|___________|
>
>Hopefully you know what I am talking about. Any help? Thanks alot,
>
>-kyle.




_________________________________________________________

Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com




  Return to Index