Jump to content

Please help!! Fwrite to excel


chantalfreak

Recommended Posts

Hi

 

I have an excel document called test.csv with a list of business names and addresses and which category the business comes under , and i want to change the category names in the excel document without going through it, i tried using find and replace but it takes to long, so i wrote this bit of code which changes the category:

 

 

<?php

 

$myFile = "test.csv";

$fh = fopen($myFile, 'w+') or die ("Could not open");

 

 

$hair = "Hairdressers / Nails / Beauty";

 

 

 

if ($stringData == "Hair"){

fwrite($fh, $stringData);

}

else

{

fwrite($fh, $hair);

 

}

fclose($fh);

 

?>

 

 

The excel looks like this

--------|--------|---------------|----------|--------|---------|

Shop | 34 |Pretend street |Ascot | berks | Hair |

--------|--------|--------------- |---------|--------|---------|

but when i run the code it looks like this:

-------------------------------|----------|--------|---------|

Hairdressers / Nails / Beauty |

------------------------------- |---------|--------|---------|

So it takes all the other info away and puts the cateory in the first box, when all i want to do is change the category name row by row so you get this

 

--------|--------|---------------|----------|--------|---------|

Shop | 34 |Pretend street |Ascot | berks | Hairdressers / Nails / Beauty |

--------|--------|--------------- |---------|--------|---------|

--------|--------|---------------|----------|--------|---------|

Shop | 34 |Pretend street |Ascot | berks | Hairdressers / Nails / Beauty |

--------|--------|--------------- |---------|--------|---------|

--------|--------|---------------|----------|--------|---------|

Shop | 34 |Pretend street |Ascot | berks | Hairdressers / Nails / Beauty |

--------|--------|--------------- |---------|--------|---------|

--------|--------|---------------|----------|--------|---------|

Shop | 34 |Pretend street |Ascot | berks | Hairdressers / Nails / Beauty |

--------|--------|--------------- |---------|--------|---------|

 

 

please help

 

Chantal

 

Link to comment
https://forums.phpfreaks.com/topic/75639-please-help-fwrite-to-excel/
Share on other sites

I tried this

 

str_replace("Hair","Hairdressers / Nails / Beauty",$myFile);

 

But how would write it within my code?

 

<?php

 

$myFile = "test.csv";

$fh = fopen($myFile, 'r+') or die ("Could not open");

 

 

$hair = "Hairdressers / Nails / Beauty";

 

 

 

if ($stringData == "Hair"){

fwrite($fh, $stringData);

}

else

{

fwrite($fh, $hair);

 

}

fclose($fh);

 

 

 

?>

 

 

Chantal

 

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.