I have a file to this effect, from which I want to retrieve the name of the opening variable $ACDF_array
using
preg_match("/\$[^\s]*/",$line,$matches);
<?php
$file = fopen(/folder/somefile.php, 'r');
$line = fgets
($file);
fclose($file);
preg_match("/\$[^\s]*/",$line,$matches); //starting with literal $ match every character until \s is reached - hopefully that is what this regex expression means
print_r($matches);
somefile.php:
<?php $ACDF_array = array (
0 =>
array (
'"No_"' => '"II00540"',
'"Manufacturer ID"' => '"MAN-ID-GNRCABNW-02"',
'"Description"' => '"GNR CAB NW-02-CRS"',
'"LQ Price"' => '"1.90000000000000000000"',
'"Retail Price Incl_ GST"' => '"14.50000000000000000000"',
'"AvailableQty"' => '"19.00000000000000000000"',
'"Rocklea"' => '"19.00000000000000000000"',
'"Sydney"' => '""',
'"Net Weight"' => '"0.10000000000000000000"',
'"Item Category Code"' => '"GNR"',
'"Product Group Code"' => '"CAB"',
'"Minor Category 1"' => '"CAB-CAT5"',
'"Minor Category 2"' => '"#"',
'"Vendor Name"' => '""',
'"Vendor URL"' => '""',
'"Item URL"' => '""',
'"Warranty"' => '""',
'"Dimension"' => '""',
'"Description1"' => '"2mt Cat5e Cross Network Cable. Compatible to all network ports, desktops and notebooks. Uptp 1000Mbps network speeds.<br />"',
'"Image"' => '"https://auscompcomputers.com/uploads/image/GNR-CAB-NW-02-CRS.jpg"',
),
1 =>
array (
'"No_"' => '"II00691"',
'"Manufacturer ID"' => '"K2A"',
'"Description"' => '"ITR KBD K2A-WHT-PS2"',
'"LQ Price"' => '"10.00000000000000000000"',
'"Retail Price Incl_ GST"' => '"23.00000000000000000000"',
'"AvailableQty"' => '"86.00000000000000000000"',
'"Rocklea"' => '"86.00000000000000000000"',
'"Sydney"' => '""',
'"Net Weight"' => '"0.50000000000000000000"',
'"Item Category Code"' => '"ITR"',
'"Product Group Code"' => '"KBD"',
'"Minor Category 1"' => '"KBD-WIRED"',
'"Minor Category 2"' => '"KBD-SINGLE"',
'"Vendor Name"' => '""',
'"Vendor URL"' => '""',
'"Item URL"' => '""',
'"Warranty"' => '""',
'"Dimension"' => '""',
'"Description1"' => '"Itron K2A Keyboard, PS2 Beige<br />"',
'"Image"' => '"https://auscompcomputers.com/uploads/image/ITR-KBD-K2A-WHT-PS2.jpg"',
),
...
Yet the only thing printed is
Array
(
[0] =>
)
I tested the regex match on regexr.com and it definitely matches what I expect it to match. Am I misunderstanding how preg_match
works?