Jump to content

display blocks of text


Ameslee

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 knackered
2) 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 (&quot; , &lt and &gt respectively in this example).

[code]
<?php
echo nl2br(htmlspecialchars($text));
?>
[/code]
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

[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!
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.