Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 29th, 2004, 12:37 PM
Authorized User
 
Join Date: Feb 2004
Location: Henley, Oxfordshire, United Kingdom.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mekh Send a message via Yahoo to mekh
Default Problem extracting DB contains to EXCEL

Hi guys,
I can't understand why \n & \t are not working in my PHP server. Its burdening me to extract the mysql datas into EXCEL format in right format but all the data goes to A1. Even
<?php
echo "This is first line \n";
echo "This is second line...";
?>
Is in single line....
Is there anything to do with php.ini, I checked it every step but i can't get any line related to it...

Thank you
Mekh
__________________
MD Gurung
Reply With Quote
  #2 (permalink)  
Old March 29th, 2004, 04:41 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's an HTML setting. HTML treats all consecutive whitespace as a single whitespace character. That allows you to write properly nested and "pretty" HTML that doesn't span way too far to the right of a text editor.

If you want to view newlines, then use a <br /> tag (line break).

If your newlines are already in your text, use the nl2br() function to add a <br /> tag to all \n newlines:

echo nl2br("This is the first line.\nThis is the second...");

  http://www.php.net/nl2br


Here's a very recent thread which addresses your question:
  http://p2p.wrox.com/topic.asp?TOPIC_ID=11219


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #3 (permalink)  
Old March 30th, 2004, 01:09 PM
Authorized User
 
Join Date: Feb 2004
Location: Henley, Oxfordshire, United Kingdom.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mekh Send a message via Yahoo to mekh
Default

Thanks Nik,

Well its working well with \n using <br /> but I actually need is \t which dump all data to one row/col in spreadsheet.
In the next thread its replaced by using &nbsp;. I don't think that will tab my data to next col.

Thank you,
Mekh



mekh dev gurung
Reply With Quote
  #4 (permalink)  
Old March 30th, 2004, 04:20 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Are you just wanting to be able to indent text?

Code:
// Query stuff

// No Carriage returns.  Remove extra newlines.  Put HTML at newlines.
// Append and Prepend HTML.  Fix quotes.
$data['body'] = preg_replace('/[\\r]/', '', $data['body']);
$data['body'] = preg_replace('[\\n]', "\n</p>\n<p class='submissionbody'>\n", $data['body']);

// The &nbsp; character will keep the line size
$data['body'] = preg_replace('/(\<p)(\\040)(class\=\'submissionbody\'\>)(\\n{1,})?(\\040{1,})?(\\n{1,})?(\<\/p\>)/', "<p class='submissionempty'>\n&nbsp;\n</p>", $data['body']);

$data['body'] = "<p class='submissionbody'>".$data['body']."</p>";
$data['body'] = stripslashes($data['body']);

$data['body'] = "<div class='submission'>".$data['body']."</div>";

echo $data['body'];
I like this method because it allows everything to be controlled with CSS. It offers a slightly more flexible approach than using the &nbsp; for tabs or the plain nl2br function. It also properly formats the paragraphs -- using spacing properties instead of HTML and puts text inside of paragraph tags. This method is still experimental for me, but I've found it works in 99% of user-submitted texts.

Throw in a few CSS rules to format..

p.submissionbody {
    text-indent: 20px;
}
p.submissionbody:first-letter {
    text-transform: uppercase;
}

: )
Rich



::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
  #5 (permalink)  
Old March 30th, 2004, 05:28 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just posted this in another thread. If you're using PHP to generate
text that looks pretty in a web page, then you'll need to fudge newlines
and tabs using non-breaking spaces. If you're using PHP to generate text
to be inserted into a spreadsheet (using CSV formatting), then obviously
your HTML hacks won't be appropriate.

First figure out what format you want to generate and generate it. Like
I said in the other thread, you can have your PHP script generate different
output from the same input data.

Other thread:
  http://p2p.wrox.com/topic.asp?TOPIC_ID=11219


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with importing excel to db -ssis collie SQL Server 2005 2 December 1st, 2007 07:07 PM
Extracting data from excel spreadsheets Neil1234567 Access VBA 2 October 16th, 2007 07:28 AM
ADO Problem fro extracting excell data mmmhbd ADO.NET 1 May 20th, 2006 02:50 AM
problem Extracting Data using HTML Object Library method VB How-To 0 May 12th, 2006 02:52 AM
excel: Extracting only selected cells. rachelrekkab Excel VBA 5 July 22nd, 2003 12:55 AM



All times are GMT -4. The time now is 08:17 PM.


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