Not too hard really…
$csvdata = file_get_contents($filepath);
$lines = explode("\n", $csvdata); // split data by new lines
foreach ($lines as $i => $line) {
$values = explode(',', $line); // split lines by commas
// set values removing them as we ago
$linevalues[$i]['name'] = trim($values[0]); unset($values[0]);
$linevalues[$i]['country'] = trim($values[1]); unset($values[1]);
$linevalues[$i]['color'] = trim($values[2]); unset($values[2]);
// assign remaining columns (array)
$linevalues[$i]['pet'] = array_values($values);
}
print_r($linevalues); // see the result
Related Posts:
- Export User Info to CSV from Front End
- file_exists() acting weird
- Export WordPress Table to CSV from page
- Custom Plugin For Converting CSV To MySQL
- Why is file_get_contents returning page source?
- How to retrieve current wordpress profile page URL?
- Cron job update csv, need help solving :-)
- Download full html page with CSV export plugin
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- Creating custom page template from existing PHP site
- ‘pre_user_query’ interfering with user export
- Custom CSV exporter – Cannot modify header information – headers
- Export WordPress User Meta to CSV/Excel
- How do I get data from my database into my Custom Export Field
- Unable to update the meta boxes with multiple fields
- Updating the database after parsing CSV document
- Front end/Database connection in WP
- Force CSV download with template_redirect
- Import users and custom user meta from csv
- Creating posts with php-script + csv
- How to add a .php file to WordPress
- When to use Exceptions vs Error Objects vs just plain false/null
- Query both first_name and last_name from wp_usermeta at the same time
- Woocommerce get selected shipping zone id for the current user
- PHP – redirect https to http and www to non-www
- Woocommerce -How to set product regular price default
- Action ‘save_post’ not working for quick edit
- Add to previous posts under post
- Limiting the WordPress feed to only a certain limit of characters
- Mail not sent when I set HTML headers
- Categories Template Assistance
- Is this code malidcous
- How to trash multiple post/product programmatically
- OrderItem get_total() returns lower value than $order_item->get_product()->get_price() * quantity
- Put CSS inside a PHP file and include it the right way
- Force SSL using FORCE_SSL_ADMIN
- Proper way to edit a post via phpMyAdmin without breaking the compare revisions tool
- Sending jsPDF documents to the server
- Unit Test in WordPress
- Sum custom field values of particular taxonomy
- Query all posts of a custom taxonomy term
- Custom Text in WooCommerce Order Processing Email Based on Products
- Add_action not working in required file of functions.php
- WordPress: get recent posts, delete the current category
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Slick + PHP + ACF + JQuery slide reveal not working
- inserting a post from an extern php file but post content doesn’t show on wp site
- Using Select HTML in Bootstrap Popovers
- Way to add captions to gallery images by code
- Building a WordPress App
- get_template_part for specific page
- proper way to add css using functions.php?
- WordPress Options Page Theory Question
- Help getting previously visited pages ID
- WordPress plugin admin page – using WordPress function in linked php file
- Any ideas why I am getting “I’m getting “wp-admin/admin-ajax.php 401 (Unauthorized)”
- Cant register rest routs from class instance
- if isset not working for undefined index, how to fix
- Decoded malware code [closed]
- Trying to enqueue script – Nothing Happens
- Undefined offset: 0-wp-includes/meta.php:488 -Melding
- How do I remove duplicate users from two merged WP_User_Query objects?
- calling function in external js file
- How can I get my Media Uploader Button to function on 1 click rather than requiring 2 clicks?
- How to refresh a page from jquery [closed]
- Woocommerce getting top level category parent and make all sub categories have the same template and menu
- Defining multiple categories for showing latest posts
- Pagination Not Working (pages duplicating content)
- Help with accessing wp-admin page and resolving error messages
- Removal of all posts content in bulk, keeping the posts itself
- using shortcodes inside gravity forms
- WordPress template file if else issue
- Trying to update Woocommerce meta values
- ssl redirect function is not working
- Hide specific shipping methode depending on day and time of day
- Adding custom field to product category and show it to shop/category shop page
- REST API custom endpoint to fetch pages and posts not working
- Create “blank” admin page without having admin-bar/admin-menu for faster load
- in_array() says array is a bool?
- adding or removing endforeach; throws error!
- Meta inserted through wp_insert_post gets messed up
- If i use a child theme to add new code blocks to header.php, how does it get inserted in the right place in parent’s header.php?
- Wp redirect – reset password
- Having issue on Loading Meta Data From CSV to CPT
- New term taxonomy and description in front page. Input’s
- Full search and replace isn’t enough to make all pictures to be loaded with https
- WordPress while loop with aphabetic counting like one, two, three
- Adding button to wordpress menu
- List users in a dropdown for login
- WordPress pagination broken on blog page, working for search results page
- Add php function into .js file (for tinyMCE button)
- How do I / Is it possible to execute an external PHP file / function inside WordPress?
- Password form redirection to belonging post
- custom contact form no longer working (because of 3.2?)
- Whats wrong with my code? Need To add String to shortcode? [closed]
- Suppress errors when using global function
- In reading settings posts are set to “blog” and I have page-blog.php but no posts
- advanced custom fields: repeater field within conditional statement [closed]
- How to pass value to add_filter wpcf7_form_tag from another function?