Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 预赛';s$matches不返回任何匹配项_Php_Regex_Preg Match - Fatal编程技术网

Php 预赛';s$matches不返回任何匹配项

Php 预赛';s$matches不返回任何匹配项,php,regex,preg-match,Php,Regex,Preg Match,我有一个这样的文件,我想从中使用 preg\u match(“/\$[^\s]*/”,$line,$matches) 我在regexr.com上测试了regex匹配,它完全符合我的预期。我是否误解了preg\u match的工作原理?如果你使用'/\$\S+/'?@WiktorStribiżew-wow,那就行了!欢迎您作为答案发布,我可以接受。您需要在您的正则表达式周围使用单引号,或者避开其中的反斜杠,即“/\\$[^\s]*/”实际上,如果您将@WiktorStribiż标记为dupe,我会

我有一个这样的文件,我想从中使用

preg\u match(“/\$[^\s]*/”,$line,$matches)


我在regexr.com上测试了regex匹配,它完全符合我的预期。我是否误解了
preg\u match
的工作原理?

如果你使用
'/\$\S+/'
?@WiktorStribiżew-wow,那就行了!欢迎您作为答案发布,我可以接受。您需要在您的正则表达式周围使用单引号,或者避开其中的反斜杠,即
“/\\$[^\s]*/”
实际上,如果您将@WiktorStribiż标记为dupe,我会受到惩罚/禁止吗?我的意思是,我根本不知道这是一个问题,因此在我知道答案之前,我不可能把它与重复的问题联系起来。
 <?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);     
<?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"',
  ),

...
Array
(
    [0] =>
)