macinslaw Posted July 20, 2007 Share Posted July 20, 2007 Trying to see if there is a way of removing quote marks from the file I am having PHP output to. Might also need some assistance with my code in the next week or so. Please remember I am a noob, not a complete newb, buta noob all the same. So any of the super advanced features I will be lost with, please use simple solutions and language, please. Thanks. -Mac Quote Link to comment Share on other sites More sharing options...
chigley Posted July 20, 2007 Share Posted July 20, 2007 <?php $string = "This is a \"string\" with 'quotation' marks in it!"; // This is a "string" with 'quotation' marks in it! $string = str_replace("'", "", $string); $string = str_replace("\"", "", $string); // This is a string with quotation marks in it! ?> Why do you want to remove them anyway? Quote Link to comment Share on other sites More sharing options...
dbo Posted July 20, 2007 Share Posted July 20, 2007 No idea what you're trying to accomplish. If you're outputting to some datafile... remove any unwanted characters before writing to the file? Quote Link to comment Share on other sites More sharing options...
macinslaw Posted July 20, 2007 Author Share Posted July 20, 2007 The following code parses a sql view, too many time in my opinion causing some rather interesting problems but that's another issue, during the collection phase, I assign the data to variables that I write to a larger "collector" variable. When it has finally come to the end of the data stream, the last step is for it to write all the data previously collected to the file DCS.txt. In the output section is a sample of the output. Notice that around some data there are quotes and around others there is not. I cannot have any quote marks in the output file. Thanks for your assistance. -Mac Code: <? $conn=odbc_connect('SomeDB,'XXXX','XXXX'); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT * FROM Sometbl"; $rs=odbc_exec($conn,$sql); if (!$rs){ exit("SQL Connection Error"); } // - This section is just to count the number of jobs for the Header //echo "1<br>"; $foot="\$END\n"; $shopnum=0; $count=0; while (odbc_fetch_row($rs)){ $shopnum=odbc_result($rs, 'shopordernumber'); if ($shnum<>$shopnum) { $count=$count+1; } $shnum=$shopnum; } //echo "2<br>"; //echo "$NUMBER/t $count<br>"; // - End section to count number of jobs // Begin section to build header $sql1="SELECT * FROM dcs_transfer_vew"; $rs1=odbc_exec($conn,$sql); if (!$rs1){ exit("SQL Connection Error"); } //echo "3<br>"; $shopnum=0; $maincount=1; while (odbc_fetch_row($rs1)){ //This is resetting the .cb variable in order to properly show the item number and specific gravity of type 'w'. unset ($cb2); unset ($pw2); //Begin creating header $schedule=E; $shopordernumber=odbc_result($rs1, 'shopordernumber'); $prodname=odbc_result($rs1, 'ProductName'); $prodcomment=odbc_result($rs1, 'ProductComment'); $lotno=odbc_result($rs1, 'LotNumber'); $totsize=odbc_result($rs1, 'BatchQuantity'); $dest=odbc_result($rs1, 'Destination'); //Check to see if it is the same job, if yes, then advance the count //check order number to see if same or new if ($shopnum<>$shopordernumber){ $timesthru=1; $maincount=1; echo "<br>shopnum=$shopnum<br>main=$maincount<br>"; /* if ($shopnum==0 and $maincount==1){ echo "do it now<br>"; $head="%Begin Recipe\n"; } */ if ($shopnum<>$shopordernumber and $maincount==1){ if ($shopnum<>0){ //echo "insert footer<br>"; $head .=$foot; $head .="%Begin Recipe\n"; } else { $head .="%Begin Recipe\n"; } } $shopnum=$shopordernumber; //Assemble header $head .= "\$schedule"; $head .= "\t"; $head .= "$schedule"; $head .= "\n"; $head .= "1-IDEMITSU1\t$shopordernumber\n"; $head .= "\$FORMULA\n"; $head .= "%START OF HEADER\n"; $head .= "#HDRDATA\n"; $head .= "PRODNAME [1,1]\t$prodname\n"; $head .= "COMMENT[1,1]\t$prodcomment\n"; $head .= "LOTNO[1,1]\t$lotno\n"; $head .= "TOTSIZE[1,1]\t$totsize\n"; $head .= "DEST[1,1]\t$dest\n"; } if ($shopnum==$shopordernumber and $timesthru<=1) { //Start of CB Data $sql2="SELECT * FROM dcs_transfer_vew where ShopOrderNumber='$shopnum' and measurementtype='W'"; //echo "$sql2<br>"; $rs2=odbc_exec($conn,$sql2); if (!$rs2){ echo "Unable to fetch dname results.<br>"; exit; } //$chknum=odbc_num_rows($rs2); //echo "numrow=$chknum<br>"; while (odbc_fetch_row($rs2)) { if ($maincount<>1){ $dd=odbc_result($rs2, 'materialname'); $ditem=odbc_result($rs2, 'formulaitem#'); $dspgr=odbc_result($rs2,'specificgravity'); $damt=odbc_result($rs2,'quantity'); $cb2 .= "DITEMNO[1,$maincount]\t$ditem\n"; $cb2 .= "DSPGR[1,$maincount]\t$dspgr\n"; $cb2 .= "DAMT[1,$maincount]\t$damt\n"; $cb ="DNAME[1,$maincount]\t$dd\n"; } else { $cb = "%START OF CB DATA\n"; $cb .= "#DRUMDATA\n"; $dd=odbc_result($rs2, 'materialname'); $ditem=odbc_result($rs2, 'formulaitem#'); $dspgr=odbc_result($rs2,'specificgravity'); $damt=odbc_result($rs2,'quantity'); $cb2 .= "DITEMNO[1,$maincount]\t$ditem\n"; $cb2 .= "DSPGR[1,$maincount]\t$dspgr\n"; $cb2 .= "DAMT[1,$maincount]\t$damt\n"; $cb .="DNAME[1,$maincount]\t$dd\n"; } // Advance the count and add the stuff we just obtained echo "cb=$cb<br>"; //echo "pw=$pw<br>"; $head .= $cb; //$head .= $pw; //$maincount=$maincount+1; //End of CB data } // Begin PWDRDATA $sqlpwdr="SELECT * FROM dcs_transfer_vew where ShopOrderNumber='$shopnum' and measurementtype='N'"; //echo "$sql2<br>"; $rspwdr=odbc_exec($conn,$sqlpwdr); if (!$rspwdr){ echo "Unable to fetch dname results.<br>"; exit; } // Begin parsing data for second part of data collection while (odbc_fetch_row($rspwdr)){ if ($maincount<>1){ echo "making it here.<br>"; $pname=odbc_result($rspwdr, 'materialname'); $pitem=odbc_result($rspwdr, 'formulaitem#'); $pamt=odbc_result($rspwdr,'quantity'); $pw2 .= "PITEMNO[1,$maincount]\t$pitem\n"; $pw2 .= "PAMT[1,$maincount]\t$pamt\n"; $pw = "PNAME[1,$maincount]\t$pname\n"; } else { echo "making it here.<br>"; //$cb = "%START OF CB DATA\n"; $pw .= "#PWDRDATA\n"; $pname=odbc_result($rspwdr, 'materialname'); $pitem=odbc_result($rspwdr, 'formulaitem#'); $pamt=odbc_result($rspwdr,'quantity'); $pw2 .= "PITEMNO[1,$maincount]\t$pitem\n"; $pw2 .= "PAMT[1,$maincount]\t$pamt\n"; $pw .= "PNAME[1,$maincount]\t$pname\n"; } //echo "cb=$cb<br>"; echo "pw=$pw<br>"; //$head .= $cb; $head .= $pw; $maincount=$maincount+1; } $head .= $cb2; $head .= $pw2; echo "pw2=$pw2<br>"; $timesthru=$timesthru+1; echo "done with cb.<br>"; }// End If shopnum, maincount and timesthru echo "Done with this part<br>"; }// End first While echo "$head"; $data=$head; $data .="\$COMPLETE"; echo "$data<br>"; $fp = fopen("DCS.txt","w"); // $fp is now the file pointer to file $filename if($fp){ //print ($data); fwrite($fp,$data); // Write information to the file fclose($fp); // Close the file echo "File saved successfully"; } else { echo "Error saving file!"; } ?> Output in text file: %Begin Recipe $schedule E 1-IDEMITSU1 11757 $FORMULA %START OF HEADER #HDRDATA "PRODNAME [1,1]" 1067 "COMMENT[1,1]" Honda 5W20 FEO-06M (US) "LOTNO[1,1]" 7FJA0008 "TOTSIZE[1,1]" 13000 "DEST[1,1]" 709 %START OF CB DATA #DRUMDATA "DNAME[1,1]" IA-401U "DNAME[1,2]" IA-585U "DNAME[1,3]" IA-730U "DNAME[1,4]" IA-362 "DNAME[1,5]" IA-625 "DITEMNO[1,1]" 7401 "DSPGR[1,1]" 0.8477 "DAMT[1,1]" 0.1 "DITEMNO[1,2]" 7585 "DSPGR[1,2]" 0.9993 "DAMT[1,2]" 0.19 "DITEMNO[1,3]" 7730 "DSPGR[1,3]" 0.9522 "DAMT[1,3]" 5.00E-02 "DITEMNO[1,4]" 8362 "DSPGR[1,4]" 1.0376 "DAMT[1,4]" 0.5 "DITEMNO[1,5]" 8625 "DSPGR[1,5]" 0.9525 "DAMT[1,5]" 9.00E-02 $END Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 20, 2007 Share Posted July 20, 2007 echo chigley that will work.. <?php $string = "This is a \"string\" with 'quotation' marks in it!"; // This is a "string" with 'quotation' marks in it! $string = str_replace("'", "", $string); $string = str_replace("\"", "", $string); // This is a string with quotation marks in it! ?> Why do you want to remove them anyway? ALSO read the rules and use code tags Quote Link to comment Share on other sites More sharing options...
macinslaw Posted July 20, 2007 Author Share Posted July 20, 2007 That code does not work for me. When I attempt to use the "\" like so: $var .= \"test\t$test\n\"; I run the script and it immediately fails and tells me that the syntax is wrong. Can you help me come up with another answer? Madtechie: Sorry It took me 10-15 mins to figure out what you were talking about as for "code tags", I don't know how, but in my spare time, I will try to find the answer in the forum here. And if I am breaking any rules, please advise me of such and what rule instead of telling me to read the rules section. I do not know of any rule of which I am in non-compliance of, please advise me on this as well, if you please so I may alter any behavour or posts in the future so as not to commit any criminal acts on this board. I like this board and would certainly like to stay in everyone's good graces. I welcome you thoughts and comments. Chigley: I must remove the quotes for a third party application that will be using the text file to create recipes based upon our data schedule. It's really nutty, the aplication can use a text file set up as tab delimited, only it can't have quotes, it has to have certain "illegal" characters, and must be arranged in a way that is making my life a living hell, not to mention that now I was told that it has to be dynamic based on the date. I've worked with date against a linux server running mysql, but not a windows server running MsSql! LOL Anyway, to answer your question, for the third party app. Believe me if I didn't have to, I wouldn't be trying to do this. Thanks. -Mac Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 20, 2007 Share Posted July 20, 2007 That code does not work for me. Can you help me come up with another answer? Thanks. -Mac In what way does it not work? What happens when you try it? Can we see the relevant code with this being used? Quote Link to comment Share on other sites More sharing options...
macinslaw Posted July 20, 2007 Author Share Posted July 20, 2007 Madtechie: Issue not resolved. I also read that section before posting. I am a seasoned pro in the computer field just new to programming, and to be honest, new to forums. I generally try to stand clear of most forums, but when you need help... That's why the only time you see me here is when I have a question or issue. Sorry, if I have posted incorrectly. I changed the entire code and received a zero output. Nada, nothiing, zip. The script would not even run. The above is an example of what I did on every line where I needed to concatenate data to a variable, which may actually be part of the issue. Please let me know what I need to do in order for you to be able to assist. I do not have access to the internet from my home, is not offered in my area, so I will not be able to work on this until Monday. I will see you all then. -Mac Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 20, 2007 Share Posted July 20, 2007 Notice that around some data there are quotes and around others there is not. I cannot have any quote marks in the output file. OK change Code: <?php $fp = fopen("DCS.txt","w"); // $fp is now the file pointer to file $filename if($fp){ //print ($data); fwrite($fp,$data); // Write information to the file fclose($fp); // Close the file echo "File saved successfully"; } else { echo "Error saving file!"; } ?> to <?php $fp = fopen("DCS.txt","w"); // $fp is now the file pointer to file $filename if($fp){ //filter $data= str_replace("'", "", $data); $data= str_replace('"', "", $data); fwrite($fp,$data); // Write information to the file fclose($fp); // Close the file echo "File saved successfully"; } else { echo "Error saving file!"; } ?> Quote Link to comment Share on other sites More sharing options...
macinslaw Posted July 23, 2007 Author Share Posted July 23, 2007 Issue resolved. Thanks very much. I greatly appreciate your time, assistance and your fine guidance. I would like to understand why this works, though. Can you please explain? Otherwise, thanks! -Mac Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 24, 2007 Share Posted July 24, 2007 See comments <?php $fp = fopen("DCS.txt","w"); // $fp is now the file pointer to file $filename if($fp){ //filter (the magic) //OK the data is about to be written to the file, so the 1st line below finds ' and replaces it with nothing //and the 2nd line below finds " and replaces it with nothing.. then the data is written.. //NOTE: the ' is enclosed with " and the 2nd lines " is enclosed with ' $data= str_replace("'", "", $data); $data= str_replace('"', "", $data); fwrite($fp,$data); // Write information to the file fclose($fp); // Close the file echo "File saved successfully"; } else { echo "Error saving file!"; } ?> hope that helps Quote Link to comment Share on other sites More sharing options...
macinslaw Posted July 27, 2007 Author Share Posted July 27, 2007 Soory, madtechie, I meant to say thank you. You were a very big help. -Mac Quote Link to comment 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.