Bug #71588 [Opn->Nab]: str_getcsv partial string enclosure

From: Date: Mon, 15 Feb 2016 00:39:50 +0000
Subject: Bug #71588 [Opn->Nab]: str_getcsv partial string enclosure
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199206@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71588&edit=1 ID: 71588 Updated by: requinix@php.net Reported by: JunkYardMail1 at Frontier dot com Summary: str_getcsv partial string enclosure -Status: Open +Status: Not a bug Type: Bug Package: Strings related Operating System: FreeBSD PHP Version: 5.6.18 Block user comment: N Private report: N New Comment: That string doesn't follow the rules for CSV. Rules which vary by implementation, admittedly, but one common rule is that embedded quotes must be themselves quoted and the containing field as a whole must be quoted as well. https://3v4l.org/c93T0 Which means CSV parsing is not suitable for your string. Regex is probably the way to go. Previous Comments: ------------------------------------------------------------------------ [2016-02-14 13:28:12] JunkYardMail1 at Frontier dot com Description: ------------ --- From manual page: http://www.php.net/function.str-getcsv --- If a string is partially in an enclosure then delimiter characters within the enclosed portion are not protected. Test script: --------------- $string = 'dhcp-class-identifier "Wireless Broadband R,outer", dhcp-client-identifier "", host-name "Wireless_Broadband_Router", domain-name "home"'; $options = str_getcsv($string, ',', '"', '\\'); foreach ($options as $option) { $send_options .= "\tsend " . trim($option) . ";\n"; } echo $send_options; Expected result: ---------------- send dhcp-class-identifier "Wireless Broadband R,outer"; send dhcp-client-identifier ""; send host-name "Wireless_Broadband_Router"; send domain-name "home"; Actual result: -------------- send dhcp-class-identifier "Wireless Broadband R; send outer"; send dhcp-client-identifier ""; send host-name "Wireless_Broadband_Router"; send domain-name "home"; ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71588&edit=1

« previous php.bugs (#199206) next »