3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = '"slug,1", slug 2, test, "slug, 3", "", ",",'; function is_valid_plugin_slug($slug) { return trim($slug, ", \t\n\r\0\x0B") !== ''; } function parse($data) { $plugins = str_getcsv( str_replace('""', '', $data ) ); return array_filter($plugins, 'is_valid_plugin_slug'); } echo "Bare str_getcsv:\n"; $plugins = str_getcsv( $data ); var_dump( $plugins ); echo "\n\nstr_getcsv with filtering:\n"; var_dump( parse( $data ) );
Output for 8.4.1 - 8.4.2
Bare str_getcsv: Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in /in/YWsue on line 19 array(7) { [0]=> string(6) "slug,1" [1]=> string(7) " slug 2" [2]=> string(5) " test" [3]=> string(7) "slug, 3" [4]=> string(0) "" [5]=> string(1) "," [6]=> string(0) "" } str_getcsv with filtering: Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in /in/YWsue on line 12 array(4) { [0]=> string(6) "slug,1" [1]=> string(7) " slug 2" [2]=> string(5) " test" [3]=> string(7) "slug, 3" }
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.4, 8.3.6 - 8.3.15
Bare str_getcsv: array(7) { [0]=> string(6) "slug,1" [1]=> string(7) " slug 2" [2]=> string(5) " test" [3]=> string(7) "slug, 3" [4]=> string(0) "" [5]=> string(1) "," [6]=> string(0) "" } str_getcsv with filtering: array(4) { [0]=> string(6) "slug,1" [1]=> string(7) " slug 2" [2]=> string(5) " test" [3]=> string(7) "slug, 3" }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Bare str_getcsv: array(7) { [0]=> string(6) "slug,1" [1]=> string(7) " slug 2" [2]=> string(5) " test" [3]=> string(7) "slug, 3" [4]=> string(0) "" [5]=> string(1) "," [6]=> string(0) "" } str_getcsv with filtering: array(4) { [0]=> string(6) "slug,1" [1]=> string(7) " slug 2" [2]=> string(5) " test" [3]=> string(7) "slug, 3" }

preferences:
78.79 ms | 410 KiB | 5 Q