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 用于按数组循环导入数据库中数据的正则表达式帮助_Php_Regex - Fatal编程技术网

Php 用于按数组循环导入数据库中数据的正则表达式帮助

Php 用于按数组循环导入数据库中数据的正则表达式帮助,php,regex,Php,Regex,我有一个文本文件,所有的问题和答案都在那里,就像下面的文本一样 question l : Regular expression problem in C# answer 1 : regular expression answer 1 question 2 : Regular expression problem in php answer 2 : regular expression answer 2 等等 我像贝娄一样做的 <question> questi

我有一个文本文件,所有的问题和答案都在那里,就像下面的文本一样

question l : Regular expression problem in C#  

answer 1 :   regular expression answer 1

question  2 : Regular expression problem in php 

answer 2 :   regular expression answer 2
等等

我像贝娄一样做的

<question> question l : Regular expression problem in C# </question> 

<answer> answer 1 : regular expression answer 1</answer>

<--page-->

<question>question 2 : Regular expression problem in php </question>

<answer>answer 2 : regular expression answer 1</answer>

<--page-->
问题l:C#中的正则表达式问题 答案1:正则表达式答案1 问题2:php中的正则表达式问题 答案2:正则表达式答案1 所以我可以创建一个数组和foreach循环,我可以将它插入到下表中的数据库中

问题id,问题答案

1 C#正则表达式中的正则表达式问题答案1

php正则表达式中的正则表达式问题解答2

任何人都可以帮助我构建正则表达式,我构建了这个正则表达式,但它在答案文本中包含问题文本

preg_match_all("#^(?<!<question>).*<question>.*?</question>(?!.*<question>)#",$temp_data,$question);
preg_match_all("#^(?<!<answer>).*<answer>.*?</answer>(?!.*<answer>)#",$temp_data,$answer);
preg#u match_all(“#^(?).*?(?!.*)#“,$temp#u data,$question);
preg#u match#u all(“#^(?).*?(?!*)#“,$temp#u data,$answer);

我不确定我是否能完全理解,但我想你想要这个

preg_match_all("#(?<=<question>).*?(?=</question>)#",$temp_data,$question);
preg_match_all("#(?<=<answer>).*?(?=</answer>)#",$temp_data,$answer);

preg_match_all(“#”)(?是的,我想获取标签内的所有文本