John Davidson

php - Should I use "fgetcsv" instead of "array_map" and how to do it?

0 comments
Message:


I've made this script to extract data from a CSV file.


$url = 'https://flux.netaffiliation.com/feed.php?maff=3E9867FCP3CB0566CA125F7935102835L51118FV4';
$data = array_map(function($line) { return str_getcsv($line, '|'); }, file($url));

It's working exactly as I want but I've just been told that it's not the proper way to do it and that I really should use fgetcsv instead.


Is it right ? I've tried many ways to do it with fgetcsv but didn't manage at all to get anything close.


Here is an example of what i would like to get as an output :


$data[4298][0] = 889698467841
$data[4298][1] = Figurine Funko Pop! - N° 790 - Disney : Mighty Ducks - Coach Bombay
$data[4298][2] = 108740
$data[4298][3] = 14.99


My Answer:
PHP is a popular server-side scripting language that is commonly used for web development. It is a versatile language that can be used for a wide range of applications, from simple websites to complex web applications.

Whether or not you should use PHP depends on your specific needs and requirements. If you are looking to build a dynamic website or web application, PHP may be a good choice for you. It has a large community of developers and a wide range of libraries and frameworks that can help you build your project quickly and efficiently.

However, if you are looking for a more modern and scalable solution, you may want to consider using a different language or framework. There are many other options available, such as Python, Ruby on Rails, or Node.js, that may better suit your needs.

Ultimately, the decision to use PHP or not should be based on your specific project requirements and your own familiarity with the language. If you are comfortable with PHP and it meets your needs, then it may be a good choice for your project.

Rate this post

3 of 5 based on 2121 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us