chantalfreak Posted November 1, 2007 Share Posted November 1, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75639-please-help-fwrite-to-excel/ Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 use str_replace on the data http://php.net/str_replace Quote Link to comment https://forums.phpfreaks.com/topic/75639-please-help-fwrite-to-excel/#findComment-382740 Share on other sites More sharing options...
chantalfreak Posted November 1, 2007 Author Share Posted November 1, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75639-please-help-fwrite-to-excel/#findComment-382756 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.