0

I am fetching data from my website using Curl. Data is fetched in HTML Table Format. So how to save the data in CSV format correctly

<?php
 $url = 'http://etea.edu.pk/result_controller';
 $ch = curl_init();
 $ch = curl_init($url);
 $params = [
   'search_res' => true,
   'search_value' => 108,
   'result_id'   => 272,
  ];
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
 $result = curl_exec($ch);
 curl_close($ch);

 $file = fopen("contacts.csv","w");
 fputcsv($file,explode(',',$result));
 fclose($file);
?>
Amir Iqbal
  • 831
  • 11
  • 28
  • You don't need to use `explode` function for writing into csv file. – Wolverine Nov 29 '16 at 16:03
  • ok. that's fine. but the data is now in html format. so how to save only text in csv.? @Perumal93 – Amir Iqbal Nov 29 '16 at 16:05
  • You can use `strip_tags` to extract only the textual content out of HTML tags. – Wolverine Nov 29 '16 at 16:06
  • i have used, but it return some of the text with no space. so can't even explode. – Amir Iqbal Nov 29 '16 at 16:08
  • Possible duplicate http://stackoverflow.com/questions/10498632/converting-html-table-to-a-csv-automatically-using-php – MarcM Nov 29 '16 at 16:09
  • MarcM has commented out the link to the question already existing. You can refer to it to get it worked. – Wolverine Nov 29 '16 at 16:11
  • @AmirIqbal Yeah. It returns text with no space wrapped around them. Therefore, you may need to work around to get it or use third party library like the one mentioned in the link provided by MarcM. – Wolverine Nov 29 '16 at 16:11

0 Answers0