Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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 如何使用正则表达式提取包含在CDATA之间的字符串部分?_Php_Regex - Fatal编程技术网

Php 如何使用正则表达式提取包含在CDATA之间的字符串部分?

Php 如何使用正则表达式提取包含在CDATA之间的字符串部分?,php,regex,Php,Regex,如何使用php提取CDATA标记中包含的字符串? 比如我有 $str = "<![CDATA[this is my text]]>"; $str=”“; 使用正则表达式如何提取字符串“这是我的文本”您可以使用此正则表达式:/: $str=”“; $matches=array(); preg_匹配('/',$str,$matches); echo$匹配项[1];//这是我的文本 正则表达式查找后跟任何字符的,。您可以使用此正则表达式:/: $str=”“; $matches=ar

如何使用php提取CDATA标记中包含的字符串? 比如我有

$str = "<![CDATA[this is my text]]>";
$str=”“;

使用正则表达式如何提取字符串“这是我的文本”

您可以使用此正则表达式:
/

$str=”“;
$matches=array();
preg_匹配('/',$str,$matches);
echo$匹配项[1];//这是我的文本

正则表达式查找后跟任何字符的

您可以使用此正则表达式:
/

$str=”“;
$matches=array();
preg_匹配('/',$str,$matches);
echo$匹配项[1];//这是我的文本

正则表达式将查找后跟任何字符的
,直到遇到第一个
]>

如果字符串始终以
开头,以
]>
结尾,则可以使用substr()

$str=”“;
$output=substr($str,9,strlen($str)-12);
echo$输出;

如果字符串总是以
开头,以
]>
结尾,则可以使用substr()

$str=”“;
$output=substr($str,9,strlen($str)-12);
echo$输出;

为什么不在中间部分使用正则<代码>(.*)<代码>?我最近在引擎里做了很多正则表达式,没有GRY和非贪婪的量词,为什么在中间部分不使用规则<代码>(?*)<代码>?最近我在一个没有greey和非贪婪量词的引擎中做了很多正则表达式,哈哈
$str = "<![CDATA[this is my text]]>";

$matches = array();
preg_match('/<!\[CDATA\[(.*?)\]\]>/', $str, $matches);
echo $matches[1]; // this is my text
$str = "<![CDATA[this is my text]]>";
$output = substr($str,9,strlen($str)-12);
echo $output;