0

您好,有人可以帮我解决这个正则表达式吗

这是我的 $lang_file:

define(words_picture,"Снимка");
define(words_amount,"бр.");
define(words_name,"Име");
define(words_price_piece,"Ед. цена");
define(words_total,"Обща цена");
define(words_del,"Изтрий");
define(words_delivery,"Доставка,но няма");

这是我的代码:

$fh = fopen($lang_file, 'r');
$data = str_replace($rep,"",fread($fh, filesize($lang_file)));
fclose($fh); 
preg_match_all('/define\((.*?)\)/i', $data,$defines,PREG_PATTERN_ORDER);

当我打印 $defines 我得到这个:

[0] => words_picture,"Снимка"
[1] => words_amount,"бр."
[2] => words_name,"Име"
[3] => words_price_piece,"Ед. цена"
[4] => words_total,"Обща цена"
[5] => words_del,"Изтрий"
[6] => words_delivery,"Доставка" //here is the part that is missing and i need it :-)

因此,当字符串中有逗号时,它会在那里破坏字符串,并且不会返回正确的值。

4

1 回答 1

0

Try (koko.*?) as the match. That'll return koko for koko,goko. If you want it to return koko,goko, remove the ?. Make it (koko.*). That will return koko,goko for koko,goko.

Here's a site that I use to test my regex against a number of cases:

http://www.cyber-reality.com/regexy.html

based on your edit I'd say you're looking for (koko.*). If your code worked for everything else, use this:

preg_match_all('\(/define.*)\)/i', $data,$defines,PREG_PATTERN_ORDER);
于 2012-11-14T18:13:02.987 回答