Ameslee Posted December 4, 2006 Share Posted December 4, 2006 Hope someone can help me? Im displaying different amounts of blocks of text, basically it's feedback. How do i display it so that it doesn't push my layout out of whack? How would you <br> when displaying from the database? sorry if this is confusing! Its confusing me!thanks Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/ Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 how do you mean pushing your layout out of whack?if youre on about lines being too long and not breaking, you'll need to do a few things to chop the lines up a bit.the way i display data from a database depends on what type of data it is. if it is data in a TEXT or BLOB field, then i generally use [url=http://www.php.net/nl2br]nl2br[/url] to maintain the line breaks as i intended. if its a case of lines being too long, then either insert a space every nth character to break the line up, or insert a HTML <wbr /> tag which some browsers support. Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134581 Share on other sites More sharing options...
Ameslee Posted December 4, 2006 Author Share Posted December 4, 2006 i see! Is there an easier way as once i have finished it will be handed over to someone else with less experience that i have? yes it is a text block! And yeah the line is too long, and its not wrapping. Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134585 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 it depends. normally, the only sort of text too wide for a site is a URL. otherwise, you need to widen your site :)non-wrapping is a result of a lack of spaces. so make some. if its a URL, i've occasionally used this:[code]<?php$text = str_replace('?', '?<wbr>', $text);$text = str_replace('&', '&<wbr>', $text);?>[/code]which inserts a "soft" line break after your &'s and ?'s. meaning - the line will appear continuous, UNLESS it needs to be broken. carefull with this one though, as browser support is a bit rubbish. Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134587 Share on other sites More sharing options...
Ameslee Posted December 4, 2006 Author Share Posted December 4, 2006 no it isnt a link!!!! Its coming from a text box! Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134588 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 are we talking someone typing lines purposely too long here?there are two other methods. either use CSS overflow:hidden, or PHP's [url=http://www.php.net/wordwrap]wordwrap()[/url] function.[code]<?php$text = "iamaridiculouslylongbitoftextthathasnospacesandisdesignedtobuggerupahtmllayout";$text = wordwrap($text, 40, "\n");?>[/code]the above will split the sentence every 40 characters with a line break. Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134590 Share on other sites More sharing options...
Ameslee Posted December 4, 2006 Author Share Posted December 4, 2006 sorry i have to explain myself a bit more clearer. Ok i have maintenance pages, that someone such as the administrator, necessarily not me, and possibly someone that doesnt know any html/php/css/etc will access, enter data. Then they press update! and there you go, it displays on the site. Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134592 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 sure - but if your layout is breaking as a result of lines that are too long, then the lines they're are entering are too long, which either means:1) their spacebar is knackered2) the code above needs to be used to chop the line up into smaller pieces that wont bust your layout.otherwise, there maybe a problem with quotes being displayed, etc. you might want to use [url=http://www.php.net/htmlspecialchars]htmlspecialchars[/url] which will convert quotes, arrows < and >, etc, into 'special' entities (" , < and > respectively in this example).[code]<?phpecho nl2br(htmlspecialchars($text));?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134595 Share on other sites More sharing options...
Ameslee Posted December 4, 2006 Author Share Posted December 4, 2006 [code]<?php$text = "iamaridiculouslylongbitoftextthathasnospacesandisdesignedtobuggerupahtmllayout";$text = wordwrap($text, 40, "\n");?>[/code]Ok to use the above code. Where do i put it within the code?Here is my code at the moment:[code]<?php $hostname = ; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db(" ", $conn); $query = "SELECT * FROM feedback"; $mysql_result=mysql_query($query,$conn); $row=mysql_fetch_row($mysql_result); $i=1; while(($row!="") && ($i<=4)) { echo("<table width=80%>"); echo "<tr>"; echo "<td width=40%><b>Feedback Received By:</b></td><td>$row[1]</td></tr>"; echo "<tr><td width=40%><b>Feedback:</b></td><td>$row[3]</td></tr>"; echo "</table><hr>"; $row=mysql_fetch_row($mysql_result); $i++; } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134599 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 anywhere you like, as long as it's AFTER you retrieve it from the DB and before you display it.[code]<?php $hostname = ; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db(" ", $conn); $query = "SELECT * FROM feedback"; $mysql_result=mysql_query($query,$conn); $row=mysql_fetch_row($mysql_result); $i=1; while(($row!="") && ($i<=4)) { // ***** HERE WILL DO ***** $row[3] = wordwrap($row[3], 40); echo("<table width=80%>"); echo "<tr>"; echo "<td width=40%><b>Feedback Received By:</b></td><td>$row[1]</td></tr>"; echo "<tr><td width=40%><b>Feedback:</b></td><td>$row[3]</td></tr>"; echo "</table><hr>"; $row=mysql_fetch_row($mysql_result); $i++; } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134605 Share on other sites More sharing options...
Ameslee Posted December 4, 2006 Author Share Posted December 4, 2006 [quote author=redbullmarky link=topic=117239.msg478190#msg478190 date=1165196856]anywhere you like, as long as it's AFTER you retrieve it from the DB and before you display it.[code]<?php $hostname = ; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db(" ", $conn); $query = "SELECT * FROM feedback"; $mysql_result=mysql_query($query,$conn); $row=mysql_fetch_row($mysql_result); $i=1; while(($row!="") && ($i<=4)) { // ***** HERE WILL DO ***** $row[3] = wordwrap($row[3], 40); echo("<table width=80%>"); echo "<tr>"; echo "<td width=40%><b>Feedback Received By:</b></td><td>$row[1]</td></tr>"; echo "<tr><td width=40%><b>Feedback:</b></td><td>$row[3]</td></tr>"; echo "</table><hr>"; $row=mysql_fetch_row($mysql_result); $i++; } ?>[/code][/quote]This didnt do anything! Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134607 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 can you post a screenshot or something of your output?[b]edit:[/b] oops sorry. you need to specify that you want it cut:[code]$row[3] = wordwrap($row[3], 40, '<br />', true);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134609 Share on other sites More sharing options...
Ameslee Posted December 4, 2006 Author Share Posted December 4, 2006 here is a screenshot!http://img.photobucket.com/albums/v619/linkinchick4eva/screenshot.jpg Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134610 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 ^ i posted an edit before. should sort you out. Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134611 Share on other sites More sharing options...
Ameslee Posted December 4, 2006 Author Share Posted December 4, 2006 thank you ;D it worked! Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134613 Share on other sites More sharing options...
Ameslee Posted December 4, 2006 Author Share Posted December 4, 2006 one more problem on that same page, if u look at the screenshot at the bottom banner, with the links on it. It goes right across the page and its meant to be in line with box. Why? Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-134624 Share on other sites More sharing options...
Ameslee Posted December 5, 2006 Author Share Posted December 5, 2006 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/29347-display-blocks-of-text/#findComment-135231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.