Jump to content

inserting tabs


AV1611

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.
Link to comment
https://forums.phpfreaks.com/topic/13836-inserting-tabs/
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.
Link to comment
https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53805
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);

?>
Link to comment
https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53808
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
Link to comment
https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53811
Share on other sites

Archived

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

×
×
  • Create New...

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.