Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
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 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 March 29th, 2004, 12:37 PM
Authorized User
 
Join Date: Feb 2004
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
 
Old March 29th, 2004, 04:41 PM
Friend of Wrox
 
Join Date: Jun 2003
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/
 
Old March 30th, 2004, 01:09 PM
Authorized User
 
Join Date: Feb 2004
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
 
Old March 30th, 2004, 04:20 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
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
::::::::::::::::::::::::::::::::::::::::::
 
Old March 30th, 2004, 05:28 PM
Friend of Wrox
 
Join Date: Jun 2003
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/





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





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