1

I'm trying to upload csv file, it uploads the csv, but the data are not correct.

How can I convert this into just string and remove the & lt;p&gt ; or the <p>?

Example of my csv file data:

**<p>\DECO APPLE GRN IN WOODEN CRATE SIZE 34X25X15.5CM PLASTIC</p>\**
user1978142
  • 7,946
  • 3
  • 17
  • 20
user3803889
  • 29
  • 1
  • 7

1 Answers1

2

You can do something like this.

$sample_string = '**<p>\DECO APPLE GRN IN WOODEN CRATE SIZE 34X25X15.5CM PLASTIC</p>\**';
echo strip_tags(html_entity_decode($sample_string));
// **\DECO APPLE GRN IN WOODEN CRATE SIZE 34X25X15.5CM PLASTIC\**

Application (if it's not malformed):

$data = array();
if (($handle = fopen('sample.csv', 'r')) !== false) {
    while (($row = fgetcsv($handle, 4096, ',', "\n")) !== false) {
        $data[] = array_map(function($var){
            return strip_tags(html_entity_decode($var));
        }, $row);
    }
    fclose($handle);
}

echo '<pre>';
print_r($data);

Output:

Array
(
    [0] => Array
    (
        [0] => PROD.product_id
        [1] => PROD.sync_2
        [2] => PROD.quantity
        [3] => PROD_DESC.name
        [4] => PROD_DESC.description
        [5] => PROD_DISC.price
    )

    [1] => Array
    (
        [0] => 1
        [1] => ABCD
        [2] => 2570
        [3] => VIP
        [4] => "\ DECO APPLE GRN IN WOODEN CRATE SIZE 34X25X15.5CM PLASTIC\"
        [5] => 0.848
    )

    [2] => Array
    (
        [0] => 1
        [1] => ABCDEFG
        [2] => 2570
        [3] => VIP 2
        [4] => "\ DECO APPLE GRN IN WOODEN CRATE SIZE 34X25X15.5CM PLASTIC\"
        [5] => 10
    )
)
user1978142
  • 7,946
  • 3
  • 17
  • 20
  • @user3803889 yes? where is the CSV file? i think that's much easier to examine – user1978142 Jul 09 '14 at 08:22
  • How can I add a csv file here sir? – user3803889 Jul 09 '14 at 08:29
  • @user3803889 if its too big, you don't need to put it in here, instead use [this](http://pastebin.com/) – user1978142 Jul 09 '14 at 08:31
  • @user3803889 is this the raw csv file? the new lines are all over the place, its not properly terminated by a newline – user1978142 Jul 09 '14 at 08:44
  • Yes that's the sample of the csv's raw file. I can't edit them because they are more that 20,000. So I need to edit them via code. – user3803889 Jul 09 '14 at 08:46
  • @user3803889 so it's like that in the first place?, your csv should be lined up correctly, check [this](http://pastebin.com/wu1jzjMB) – user1978142 Jul 09 '14 at 08:51
  • @user3803889 usually, rows are pretty much lined up properly, iknow its a bit off topic, so this is the only copy you can work with, that's a pain to edit since as you have said thats 20,000+ – user1978142 Jul 09 '14 at 09:06
  • I have another question, can I make a progress bar while uploading the csv? For example, "1000 of 30000"??? – user3803889 Jul 09 '14 at 09:24
  • @user3803889 of course this is a separate question, but to give you an idea, check this out [link](http://stackoverflow.com/questions/7049303/show-progress-for-php-long-script), probably there are some other good answers here on SO – user1978142 Jul 09 '14 at 10:10
  • Can you give me a code using code igniter? Because I'm new to code igniter. – user3803889 Jul 10 '14 at 01:50
  • @user3803889 about csv? i don't know if codeigniter has wrapper functions for csv, check out their [manual](http://www.ellislab.com/codeigniter/user-guide/), if they have one. – user1978142 Jul 10 '14 at 01:54