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
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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.