Jump to content

alternative to wordwrap.


jasonc

Recommended Posts

I am hoping that this can be done using HTML

 

is there an opposite to 'nowrap'  (<td NOWRAP><?=$username;?></td>)

 

instead of what i have below that i am currently using, which adds more to the output. meaning the '<br />\n'

 

this is causing problems with the text being copied. say using the double click on text method.

 

...
...
...

<td><? echo wordwrap($text, 11, "<br />\n", true); ?></td>
....
..
..

Link to comment
Share on other sites

what i mean is so no extra characters are added to what will be outputted.

 

<table>
  <tr>
    <td width="11"><?
$text = "abcdefghijksdflkjashdflkahfljkhasdfkljhasdfklashflkhasdflkjhadljkhaljksdh";
echo ($text);
?></td>
  </tr>
</table>

Link to comment
Share on other sites

ah

 

I doubt it matters but have you assigned the output of wordwrap to a var and echoed that???

 

Just as the examples do in the docs..

 

<?php
$text = "abcdefghijksdflkjashdflkahfljkhasdfkljhasdfklashflkhasdflkjhadljkhaljksdh";
$newtext = wordwrap($text,11,"<br />",true);
echo ($newtext);
?>

 

Link to comment
Share on other sites

yes ture.

 

but now if you were to double click on this text that would have been echo'd

 

you would only be selecting one line and not all of the text that was echo'd as it now contains <b /> 's

 

this is what i need not to be there but still to have the line break up after so many characters.

Link to comment
Share on other sites

if this were in a text file then you would need something like this...

 

<?php
$text = "abcdefghijksdflkjashdflkahfljkhasdfkljhasdfklashflkhasdflkjhadljkhaljksdh";
$newtext = wordwrap($text,11,PHP_EOL ,true);
// if you uare using php < 5 or < 4.3 then it would be \r\n for windows \n for *nix and \r for Mac
echo ($newtext);
?>

 

However you want this in a web page so you HAVE to have the <br /> otherwise the whites space is truncated and you will get the text on the same line until it runs out of space...

Link to comment
Share on other sites

Well now we are getting somewhere.

 

Make your TD look like this:

 

<td class="this_class">jsdfasdfdasjfkdla;fjkd;ajfd;afjdka</td>

 

And add this to the head of your document:

<style type="text/css">
    .this_class
    {
        width: ____px; //set the width you want in pixels here
    }
</style>

 

If you want other cells to be the same width, give them the same class name ("this_class").

 

When using tables, you only need to set the class name to the cell in the top row - the cells below will all conform to that width (or such has been the case for me up until this point, but I haven't used tables much since learning CSS).

Link to comment
Share on other sites

i only want to change the first column. so the first column is so many letters wide

 

 

________

as you can see this is what i now have and it does not seem to work correctly?!

 

i have tested in FireFox and IE both show the same, but the line is not dropping to the next line when it reaches the max width i set

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.this_class
{
width: 150px; //set the width you want in pixels here
}
</style>
</head>

<body>
<table width="634">
  <tr>
    <td class="this_class">h1 long line</td>
    <td width="97">h2</td>
    <td width="100">h3</td>
    <td width="123">h4</td>
    <td width="141">h5</td>
  </tr>
  <tr>
    <td>dddddddddddddddddddddddkkkkkkkkkkkkkkkkkkkkkkyyyyyyyyyyyyyyyyyyyyyyffffffffffffffffffffffffffffffffff</td>
    <td>h2 text</td>
    <td>h3 text</td>
    <td>h4 text</td>
    <td>h5 text</td>
  </tr>
</table>

</body>
</html>

Link to comment
Share on other sites

this is the full code

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.this_class
{
width: 150px; //set the width you want in pixels here
}
</style>
</head>

<body>
<table width="634">
  <tr>
    <td class="this_class">h1 long line</td>
    <td width="97">h2</td>
    <td width="100">h3</td>
    <td width="123">h4</td>
    <td width="141">h5</td>
  </tr>
  <tr>
    <td class="this_class">dddddddddddddddddddddddkkkkkkkkkkkkkkkkkkkkkkyyyyyyyyyyyyyyyyyyyyyyffffffffffffffffffffffffffffffffff</td>
    <td>h2 text</td>
    <td>h3 text</td>
    <td>h4 text</td>
    <td>h5 text</td>
  </tr>
</table>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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