Jump to content

Archived

This topic is now archived and is closed to further replies.

AV1611

inserting tabs

Recommended Posts

If I do this:
$out="word1\tword2";
I get that when I fwrite it to file
if I do this:
$out="word1 \t word2";
I get word with the tab, but I get the space between word and the tab.
If I do this:
$tab="\t";
$out="word1".$t."word2"...
same problem

Q:  How do I set the $out so the column headers in the csv I'm making doesnt' have the extra spaces? It isn't a problem in the query return, but I'm doing that like this:

$out=$row[0]."\t".$row[1].... etc.

Share this post


Link to post
Share on other sites
Try:
[code]<?php $out = implode("\t",$row); ?>[/code]
This will put a tab character between each element of $row.

Ken

Share this post


Link to post
Share on other sites
I know it isn't the best solution but it works:

[code]
$out = array();
foreach($row as $tmp) {
  array_push($out, $tmp);
}
$out = implode('\t', $out);[/code]

Share this post


Link to post
Share on other sites
How are you outputting $out?

If you are sending it to the browser the browser will not show the tab, but show a space between word1 and word2, howver if you look into the source you'lll see the tab is there. browser ignores white spaces characters.

If you are sending it a file then it should put a tab between word1 and word2

Or do you want it to to store \t in the file as is with out it creating a tab? If you dont want it to create a tab use this:
\\t instead, two backslashes.

Share this post


Link to post
Share on other sites
I have no problem witht he row returns... I can't get the tabs in the HEADERS for the csv file:

here is the script:

<?php
$OUTPUT='';
$i=0;
$tab='\t';
$file = "./VQ1.TXT";
$fp = fopen($file,"a");
//****** the next like is the problem
$OUTPUT = "line".$tab."it_date \t insptype \t process \t product \t serialno \t step \t step_desc \t hi \t lo \t units \t actual \t gonogo \t passed";
//****** everything from here down is fine...
fwrite($fp, $OUTPUT."\n");
$connect = odbc_connect("QES9000", "", "");
$query = "SELECT
    itdatshta.`it_date`, itdatshta.`insptype`, itdatshta.`process`, itdatshta.`product`, itdatshta.`serialno`, itdatshta.`failed`,
    itdatshtda.`descr`, itdatshtda.`hi`, itdatshtda.`lo`, itdatshtda.`units`, itdatshtda.`actual`, itdatshtda.`gonogo`, itdatshtda.`step`
FROM
    `itdatshta` itdatshta INNER JOIN `itdatshtda` itdatshtda ON
        itdatshta.`datshtid` = itdatshtda.`datshtid` AND
    itdatshta.`sample` = itdatshtda.`sample`
WHERE
    itdatshta.`product` like 'T%SS3%' AND
    (itdatshta.`process` = 'VQ Functional Outputs' OR
    itdatshta.`process` = 'VQ Functional Inputs' OR
    itdatshta.`process` = 'QA Evaluation' OR
    itdatshta.`process` = 'Functional Test') AND
    itdatshta.`failed` = 0 AND itdatshta.`it_date` < {d '2006-06-26'}
ORDER BY
    itdatshta.`it_date` ASC,
    itdatshta.`serialno` ASC,
    itdatshta.`process` ASC";

$result = odbc_do($connect, $query);
WHILE($row=odbc_fetch_array($result))
{

$OUTPUT = $i."\t".rtrim($row['it_date'])."\t".rtrim($row['insptype'])."\t".rtrim($row['process'])."\t".rtrim($row['product'])."\t".rtrim($row['serialno'])."\t".rtrim($row['step'])."\t".rtrim($row['descr'])."\t".rtrim($row['hi'])."\t".rtrim($row['lo'])."\t".rtrim($row['units'])."\t".rtrim($row['actual'])."\t".rtrim($row['gonogo'])."\t YES";
//$file = "./VQ1.TXT";
//$fp = fopen($file,"w");
fwrite($fp, $OUTPUT."\n");

}
fclose($fp);
odbc_close($connect);

?>

Share this post


Link to post
Share on other sites
Put the header strings into an array and use the implode() technique I described earlier.
[code]<?php
$hdr = array('line','it_date','insptype','process','product','serialno','step','step_desc','hi','lo','units','actual','gonogo','passed');
fwrite($fp, implode("\n",$hdr)."\n");
?>[/code]

Ken

Share this post


Link to post
Share on other sites
Thanks for spelling it out for me Ken, on that last post...

Share this post


Link to post
Share on other sites
I goofed on my last post .... the first "\n" in the implode() should be a "\t".

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.