Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 01-18-2004, 11:04 PM   #1
Member (10 bit)
 
Join Date: Nov 2001
Posts: 610
Send a message via Yahoo to MSIuser
php encode text upload to database

I have an article submission script that I wrote which uploads an article to a database. I then use php to access it again, only when i echo or print it, the line spaces dont show up. Therefore I'm looking to know if there is a way to encode a variable string which has line breaks to instead have
tags. It's basically how do I manage what this forum script does when someone uploads something like

hello

help

me

in order to get the line breaks into html.
MSIuser is offline   Reply With Quote
Old 01-19-2004, 03:26 AM   #2
Member (6 bit)
 
Join Date: Sep 2002
Location: Scotland
Posts: 50
Have you tried out the fread or fopen function to check if the line is blank?

I think at the end of each line, there is some sort of code that says '\r\n'. \r and \n means end of line.

fread
http://uk2.php.net/manual/en/function.fread.php

fopen
http://uk2.php.net/manual/en/function.fopen.php

You could validate the length of the line say like

PHP Code:
//read text from file

// run WHILE loop

// line from text file is placed in a variable
// called $line
$line linefromfile;

// get length of line from text file
$linelength strlen($line);

// validate length of line
if ($linelength == 0) {
     
//ignore blank line

} else {
    
// print line full of text
    
print ($line ."<br>");
}

// end WHILE loop 
I have started using PHP a few months ago, so I may be wrong about the code above and it could be better.

Last edited by Jova; 01-19-2004 at 03:29 AM.
Jova is offline   Reply With Quote
Old 01-19-2004, 07:18 AM   #3
Staff
Premium Member
 
mairving's Avatar
 
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
Pretty easy to do using PHP's nl2br function. Basically it will add a BR at each newline for you.
mairving is offline   Reply With Quote
Old 01-25-2004, 05:09 PM   #4
Member (10 bit)
 
Join Date: Nov 2001
Posts: 610
Send a message via Yahoo to MSIuser
Thanks marving, ended up finding that solution when I started reading through a dedicated php forum. Also using the str_replace() as well.
MSIuser is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:45 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2