raman Posted September 23, 2008 Share Posted September 23, 2008 Though I give fixed width attribute for each <td> tag , when the data in the cell is too long it extends further and I have to scroll thru the browser to read the entire data.I want the text to wrap after a certain convenient limit even if there are no new line characters in the cell data. I have the PHP script as under: <?php $con= mysql_connect("localhost","root","passor3"); if(!$con) { die('Could not connect:'.mysql_error()); } mysql_select_db("Protvirdb",$con); $key=$HTTP_GET_VARS["sn"]; $rer=mysql_query("SELECT * FROM cryptovir WHERE SNo='$key'"); $special=mysql_fetch_array($rer); echo"<table align='center' border='2' width='620'> <tr><th BGCOLOR='#99CCFF' width='20'>Protein name</th>"; echo"<td width='600'>".$special['Name']."</td></tr>"; echo"</tr> <th BGCOLOR='#99CCFF' width='20'>Accession number</th>"; echo"<td width='600'>".$special['Accession']."</td></tr>"; echo"<tr> <th BGCOLOR='#99CCFF' width='20' >Pubmed Id </th>"; echo"<td width='600'>".$special['PMID']."</td></tr>"; echo"<tr> <th BGCOLOR='#99CCFF' width='20'>Sequence</th>"; echo"<td width='600'>".$special['Sequence']."</td></tr>"; echo"</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/125418-wrap-text-in-html-tables/ Share on other sites More sharing options...
JasonLewis Posted September 23, 2008 Share Posted September 23, 2008 Sounds like you want wordwrap(). Link to comment https://forums.phpfreaks.com/topic/125418-wrap-text-in-html-tables/#findComment-648441 Share on other sites More sharing options...
raman Posted September 23, 2008 Author Share Posted September 23, 2008 <?php $con= mysql_connect("localhost","root","pichii13"); if(!$con) { die('Could not connect:'.mysql_error()); } mysql_select_db("Protvirdb",$con); $key=$HTTP_GET_VARS["sn"]; $rer=mysql_query("SELECT * FROM cryptovir WHERE SNo='$key'"); $special=mysql_fetch_array($rer); $pd=$special['PMID']; $newpd= wordwrap($pd,20,"<br />\n","TRUE"); echo"<table align='center' border='2' width='620'> <tr><th BGCOLOR='#99CCFF' width='20'>Protein name</th>"; echo"<td width='600'>".$special['Name']."</td></tr>"; echo"</tr> <th BGCOLOR='#99CCFF' width='20'>Accession number</th>"; echo"<td width='600'>".$special['Accession']."</td></tr>"; echo"<tr> <th BGCOLOR='#99CCFF' width='20' >Pubmed Id </th>"; echo"<td width='600'>".$newpd."</td></tr>"; echo"<tr> <th BGCOLOR='#99CCFF' width='20'>Sequence</th>"; echo"<td width='600'>".$special['Sequence']."</td></tr>"; echo"</table>"; ?> Even after using wordwrap function I found no difference at all in the output. Link to comment https://forums.phpfreaks.com/topic/125418-wrap-text-in-html-tables/#findComment-648471 Share on other sites More sharing options...
JasonLewis Posted September 23, 2008 Share Posted September 23, 2008 Try this: $newpd= wordwrap($pd,20,"<br />",true); Link to comment https://forums.phpfreaks.com/topic/125418-wrap-text-in-html-tables/#findComment-648476 Share on other sites More sharing options...
raman Posted September 23, 2008 Author Share Posted September 23, 2008 This also did not make any difference.I got the same output. Link to comment https://forums.phpfreaks.com/topic/125418-wrap-text-in-html-tables/#findComment-648523 Share on other sites More sharing options...
raman Posted September 23, 2008 Author Share Posted September 23, 2008 Finally it worked. Actually There was another problem in the script. But for the wordwrap function I am intrigued what is the difference between "<br>\n" and "\n\n". I mean both <br> tag and \n mean the same thing.Isn't it ? Link to comment https://forums.phpfreaks.com/topic/125418-wrap-text-in-html-tables/#findComment-648538 Share on other sites More sharing options...
radalin Posted September 23, 2008 Share Posted September 23, 2008 The difference between br tag and the \n is that, tag is parsed by the browser and \n is not. Add as much new lines to your html page and new lines are not seen. You have to use a function like nl2br() to convert new lines to br. Link to comment https://forums.phpfreaks.com/topic/125418-wrap-text-in-html-tables/#findComment-648616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.