Current location: Hot Scripts Forums » Programming Languages » PHP » Problems php/msql


Problems php/msql

Reply
  #1 (permalink)  
Old 07-15-04, 06:38 AM
Elektronaut Elektronaut is offline
Newbie Coder
 
Join Date: May 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Problems php/msql

hey...

for my site im making a news and a guestbook script, and everything works just fine, except for one thing:

when i type a news message or a guestbook message, and i try to make it look neat by pressing enter between alineas, it comes out as one big long tekst without any layout... i know i can just press some <br> into my news mssg, but for a guestbook its a bit odd to ask the people to type <br> everytime they want to make a new alinea...

i hope some of you know what to do to help with this problem

thx in advance
Reply With Quote
  #2 (permalink)  
Old 07-15-04, 12:47 PM
cmonkey's Avatar
cmonkey cmonkey is offline
Newbie Coder
 
Join Date: Jul 2004
Location: Pittsburgh, PA
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
use the nl2br() function on the submitted string, that will replace all newline characters entered in the textbox to the html <br> tag.

for more info visit php.net
Reply With Quote
  #3 (permalink)  
Old 07-16-04, 12:50 AM
mikaelf mikaelf is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
you may also write your own text parser like this:
PHP Code:



//Carriage line feed
$crLf '\r\n';

//Function: normalizeString, to avoid text flooding
    
function normalizeString ($text$divider '') {
        if(
$divider '' || !is_int($divider))
            
$divider 60;
        
$arrayText explode(' ',$text);
        for(
$i=0$i<count($arrayText); $i++) {
            if((
$arrLen strlen($arrayText[$i])) > $divider) { //set max string length into divider
                
if($arrLen 0) {
                    
$totElement ceil($arrLen $divider);                
                    for(
$j=0$j<$totElement$j++) {
                        
$pos $j*$divider;
                        
$returned .= substr($arrayText[$i],$pos,$divider).' ';
                    }
                }
            }
            else {
                
$returned .= $arrayText[$i].' ';
            }
        }
        unset(
$arrayText);
        return 
$returned;
    }

//Assume you have variable $_POST['newsBody'] where the text resides

//Normalize all data first
$myText normalizeString($_POST['newsBody'],70);
$myText preg_replace($crLf,'<br />',$myText);

print 
$myText;

?> 
Wish this helps
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pop up problems w/ IE6 maksimus JavaScript 4 05-29-04 01:49 AM
trying to set up a apache,php,mysql test server, but having problems Primitive_screw PHP 3 02-13-04 04:19 PM
2 spacing/alignment problems Arowana HTML/XHTML/XML 0 01-07-04 11:58 AM
image submit button problems Pepe PHP 10 12-22-03 08:15 PM


All times are GMT -5. The time now is 05:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.