Hi,
Thanks for the replies bkennedy and markl999.
I had tried you example script out first of all bkennedy where it write the results to my file. I then added more columns to be writed to the new file, but for some reason then, it was not writing the information to the new file for some reaon so I then tried markl999's example, which worked fine.
I added more columns to it so they could be written to the new file and things went fine.
The only problem that I have with it now is that the first line is still being displayed in the text file that is written. This first line is the headings, which I don't want to be included.
This is the text file that I tried to delimit and write:
PHP Code:
ProductID|Name|MerchantID|Merchant|Link|Thumbnail|BigImage|Price|RetailPrice|Category|SubCategory|Description|Custom1|Custom2|Custom3|Custom4|Custom5|LastUpdated
453368991|10" Woodworker&39;s Table Saw with 30" Fence|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453368991|http://images.acmehardware.com/200x200/4291225.jpg|http://images.acmehardware.com/200x200/4291225.jpg|1042.56||Home/Family|Home Improvement|Accurate, dependable fence delivers smooth action Cast iron trunnion provides solid arbor support Blade elevation crank with adequate hand clearance Accurate blade angle adjustments Large, easy-access on/off switch Equipped with a Dust Collection Por||||Power Tools:Saws:Table Saws|DeWalt|2004-09-07 18:49:23.53
453345406|Dlx Stainless Steel Gas Grill|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453345406|http://images.acmehardware.com/200x200/3314044.jpg|http://images.acmehardware.com/200x200/3314044.jpg|964.93||Home/Family|Home Improvement|Features stainless steel side shelves Polished welds & spring handle H-D 16 ga stainless steel construction Reliable spark ignitor-24,000 BTU output Dual controls for temp range 550-300 degrees Warranty:10 years on Stainless Steel drip pan & lifetime- on ||||AcmeHardware.com:New Items:New Specials - Just Added|Phoenix Grill|2004-09-07 18:49:23.53
453368840|5500 Watts Generator|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453368840|||923.04||Home/Family|Home Improvement|||||AcmeHardware.com:New Items:New Specials - Just Added|Porter Cable|2004-09-07 18:49:23.53
453342557|5.5 HP Gas 8 Gallon Portable Compressor|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453342557|http://images.acmehardware.com/200x200/4203147.jpg|http://images.acmehardware.com/200x200/4203147.jpg|903.46||Home/Family|Home Improvement|5.5 HP Honda GX gas engine provides proven reliability and durability Twin cylinder, cast iron, oil lubricated pump for durability and reliability Ball drain valve allows for quick and thorough tank draining Automatic idle control for reduced fuel c||||AcmeHardware.com:New Items:New Specials|DeWalt|2004-09-07 18:49:23.53
453345405|Stainless Gas Grill|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453345405|http://images.acmehardware.com/200x200/3314036.jpg|http://images.acmehardware.com/200x200/3314036.jpg|856.1||Home/Family|Home Improvement|Die cast aluminum end caps Full length perforated stainless steel handle H-D 16 ga construction-polished stainless steel 24,000 BTU output-Dual controls with- temperature range from 550 to 300 degrees Reliable spark ignitor Warranty:10 years on Stainless ||||AcmeHardware.com:New Items:New Specials - Just Added|Phoenix Grill|2004-09-07 18:49:23.53
453329640|Tankless Water Heater|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453329640|||738.94||Home/Family|Home Improvement|||||Plumbing:Water Heaters & Parts:Electric Water Heaters|Controlled Energy|2004-09-07 18:49:23.53
453339218|16d Masonry Cut Nails|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453339218|http://images.acmehardware.com/200x200/0102186.jpg|http://images.acmehardware.com/200x200/0102186.jpg|100.1||Home/Family|Home Improvement|Ideal for nailing furring strips to cinder blocks Also for nailing to new concrete & brick walls Blunt point & tapered shank Less spalling during nailing Hold tighter than round wire nails Also used to face-nail hardwood flooring 3-1/2"||||AcmeHardware.com:New Items:New Specials|Maze Nails|2004-09-07 18:49:23.53
453332792|Wh Showercove Shwr Surrnd|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453332792|http://images.acmehardware.com/200x200/5130703.jpg|http://images.acmehardware.com/200x200/5130703.jpg|100.1||Home/Family|Home Improvement|Five-panel shower surround Adjustable 32" to 36" Use with 32WL, 34WL, 36WL, 9950, 9951||||AcmeHardware.com:New Items:New Specials - Just Added|Crane|2004-09-07 18:49:23.53
453326606|Quickwire Push-in & Sidewire|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453326606|http://images.acmehardware.com/200x200/5751425.jpg|http://images.acmehardware.com/200x200/5751425.jpg|100.08||Home/Family|Home Improvement|Rated: 15A - 125V Grounding Contractors Pack 10 per pack Ivory||||Electrical:Receptacles:Duplex Receptacles|Leviton|2004-09-07 18:49:23.53
453326607|Quickwire Push-in & Sidewire|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453326607|http://images.acmehardware.com/200x200/5751433.jpg|http://images.acmehardware.com/200x200/5751433.jpg|100.08||Home/Family|Home Improvement|Rated: 15A - 125V Grounding Contractors Pack 10 per pack White||||Electrical:Receptacles:Duplex Receptacles|Leviton|2004-09-07 18:49:23.53
453341386|Drywall Screwdriver (Variable Speed, Reversible)|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453341386|http://images.acmehardware.com/200x200/4260139.jpg|http://images.acmehardware.com/200x200/4260139.jpg|99.97||Home/Family|Home Improvement|6.5 Amp, 0-6,000 RPM Silent Synchronized Pin Clutch Retractable Belt Clip Lightweight Cast Aluminum Gear Housing Adjustable Depth Locator with Sure-Lock Forward/Reverse Switch Near Trigger Includes: (1)2 Phillips Insert Bit Magnetic Bit Holder & ||||AcmeHardware.com:New Items:New Specials - Just Added|Makita|2004-09-07 18:49:23.53
453351350|W.H. Maze 3/4" masonry nails|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453351350|http://images.acmehardware.com/200x200/1112671.jpg|http://images.acmehardware.com/200x200/1112671.jpg|99.91||Home/Family|Home Improvement|3/4" hardened steel masonry nails with9 gauge, fluted shank and a flat head. 50 lb. box.||||Hardware:Nails:Concrete & Masonry Nails|Maze Nails|2004-09-07 18:49:23.53
453339303|3 Ia Fiber Step Ladder|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453339303|http://images.acmehardware.com/200x200/6075865.jpg|http://images.acmehardware.com/200x200/6075865.jpg|99.88||Home/Family|Home Improvement|Tool-Tra-Top includes: Dual drill holsters, tool & paint can holders Small parts tray Ideal for one or two person jobs 300 lb. capacity per side of ladder Drill not included||||AcmeHardware.com:New Items:New Specials|Werner|2004-09-07 18:49:23.53
453336196|2+2 3.5 Raise Panel Bit|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453336196|http://images.acmehardware.com/200x200/4495719.jpg|http://images.acmehardware.com/200x200/4495719.jpg|99.8||Home/Family|Home Improvement|Shims included to adjust tongue thickness 54-562 radius backcutter included Cuts all composition materials, plywood Hard wood and soft wood Use on table mounted portable routers 1/2" shank diameter Size: overall diameter x carbide height||||AcmeHardware.com:New Items:New Specials|Freud|2004-09-07 18:49:23.53
453325407|26 1-1/8 Cl108 Pine Bifold|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453325407|http://images.acmehardware.com/200x200/7775299.jpg|http://images.acmehardware.com/200x200/7775299.jpg|99.72||Home/Family|Home Improvement|Three raised panels Clear stiles 1 Finger joint stiles Thickness: 1-1/8" Height: 81" Hardware included||||TBD Categories:Categories:TBD|Ledco|2004-09-07 18:49:23.53
453350228|White Aluminum Round Column|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453350228|http://images.acmehardware.com/200x200/1919018.jpg|http://images.acmehardware.com/200x200/1919018.jpg|99.66||Home/Family|Home Improvement|For residential & commercial use Also for construction & renovation Maintenance free, easy to assemble Includes cap & base Column height: 8&39; Color: white Type: round White||||TBD Categories:Categories:TBD|Afco Industries|2004-09-07 18:49:23.53
453342825|Open Slide Ii Shelf|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453342825|http://images.acmehardware.com/200x200/4190906.jpg|http://images.acmehardware.com/200x200/4190906.jpg|99.54||Home/Family|Home Improvement|Durabe and strong Open slide rod for more storage Color: white 12" depth||||AcmeHardware.com:New Items:New Specials|Schulte|2004-09-07 18:49:23.53
453332072|Moen single handle tub and shower combination fitting|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453332072|http://images.acmehardware.com/200x200/5142070.jpg|http://images.acmehardware.com/200x200/5142070.jpg|99.42||Home/Family|Home Improvement|Washerless single handle tub and shower combination fitting with contemporary lever. Pressure balance prevents scalding surprises. Includes diverter spout, showerhead, arm, and flange. Limited lifetime warranty||||Kitchen & Bath:Tub & Shower Fittings:Tub/Shower Valve Kits|Moen|2004-09-07 18:49:23.53
453351945|5g Concrete F&d Sealer|3351|AcmeHardware.com|http://www.shareasale.com/m-pr.cfm?merchantID=3351&userID=71112&productID=453351945|||99.16||Home/Family|Home Improvement|Clear gloss sealer for bare concrete Lower VOC content- than high performing urethanes Covers 200 - 300 sq. ft. per gallon Produces a hard, clear film when dry Non-yellowing, good gloss retention||||AcmeHardware.com:New Items:New Paint|Convenience Products|2004-09-07 18:49:23.53
And this is the script that I have so far:
PHP Code:
//the new headings
$headings = array('Merchant','Link','Name','Description','Thumbnail','Category','Price');
$out[] = join("\t", $headings);
//the array slice skips the first line of the file (the line with the headings)
foreach(array_slice(file('acmedone.txt'), 1) as $line)
{
$parts = explode('|', $line);
$new = array();
$new[] = $parts[3];
$new[] = $parts[4];
$new[] = $parts[1];
$new[] = $parts[11];
$new[] = $parts[5];
$new[] = $parts[9].' > '.$parts[10];
$new[] = $parts[7];
$out[] = join("\t", $new);
}
//echo the output to test
echo join('<br />', $out);
//write the new file
$fp = fopen('C:\phpdev\www\produpload\convert/acmehardware1.txt', 'w');
fputs($fp, join("\n", $out));
fclose($fp);
I hope you can help me with this!
Thanks!
Bookmarks