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>\** 
0

1 Answer 1

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 ) ) 
Sign up to request clarification or add additional context in comments.

11 Comments

@user3803889 yes? where is the CSV file? i think that's much easier to examine
How can I add a csv file here sir?
@user3803889 if its too big, you don't need to put it in here, instead use this
@user3803889 is this the raw csv file? the new lines are all over the place, its not properly terminated by a newline
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.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.