AV1611 Posted July 6, 2006 Share Posted July 6, 2006 If I do this:$out="word1\tword2";I get that when I fwrite it to fileif 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 problemQ: 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. Quote Link to comment https://forums.phpfreaks.com/topic/13836-inserting-tabs/ Share on other sites More sharing options...
kenrbnsn Posted July 6, 2006 Share Posted July 6, 2006 Try:[code]<?php $out = implode("\t",$row); ?>[/code]This will put a tab character between each element of $row.Ken Quote Link to comment https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53803 Share on other sites More sharing options...
CheesierAngel Posted July 6, 2006 Share Posted July 6, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53804 Share on other sites More sharing options...
wildteen88 Posted July 6, 2006 Share Posted July 6, 2006 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 word2Or 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. Quote Link to comment https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53805 Share on other sites More sharing options...
AV1611 Posted July 6, 2006 Author Share Posted July 6, 2006 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);?> Quote Link to comment https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53808 Share on other sites More sharing options...
kenrbnsn Posted July 6, 2006 Share Posted July 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53811 Share on other sites More sharing options...
AV1611 Posted July 6, 2006 Author Share Posted July 6, 2006 Thanks for spelling it out for me Ken, on that last post... Quote Link to comment https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53815 Share on other sites More sharing options...
kenrbnsn Posted July 6, 2006 Share Posted July 6, 2006 I goofed on my last post .... the first "\n" in the implode() should be a "\t".Ken Quote Link to comment https://forums.phpfreaks.com/topic/13836-inserting-tabs/#findComment-53851 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.