Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2005, 11:50 AM
Authorized User
 
Join Date: Dec 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Line breaks question

Hello all,

This may be more of a mysql question but anyway...

I have a website thats content is generated from a mysql database. The data is stored in a longtext column type.

The problem I have is that when I retrieve this data any line breaks or paragraphing disappear and the text appears as one long block of text.

Any ideas...

 
Old February 25th, 2005, 04:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, first, you need to input the data via <textarea> type input fields. That'll presevre the formatting (but I assume you're doing that).

Next, look into using preg_replace (http://uk.php.net/manual/en/function.preg-replace.php) and using a list of the control codes (e.g. /t for tab, /r or /n for newline - or both on WierdOS, of course!) and replaceing them with <br>s, sets of &nbsp;'s, etc..

Here's a reply I wrote ages ago, to this effect. That 'rich_text_format' function might be something like what you need:
http://p2p.wrox.com/topic.asp?TOPIC_...ch_text_format
 
Old February 27th, 2005, 10:40 AM
Authorized User
 
Join Date: Jul 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajuru Send a message via Yahoo to rajuru
Default

I think the following method is easier:
1. Input the data in a TextArea
2. when storing data to mysql use:
   nl2br($yourinput)

3. simply retrieve data from mysql. you will get data with line break.

hope this will work


Best Regard:
Md. Zakir Hossain (Raju)
www.rubd.net
www.xenex.rubd.net
www.forum.rubd.net





Similar Threads
Thread Thread Starter Forum Replies Last Post
line breaks mister_mister XSLT 14 March 17th, 2008 12:55 PM
How to do line breaks! Apocolypse2005 Beginning VB 6 2 December 11th, 2006 03:20 PM
Want to detect line breaks conundrum Classic ASP Basics 1 October 3rd, 2003 04:05 AM
problems with line breaks sanchezal XSLT 7 July 30th, 2003 03:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.