[英]How to get commented string using regular expression in PHP?
我正在尝试使用php中的正则表达式获取代码中的注释字符串。
假设我有以下字符串。
$string = "
///<summary>
///test
///</summary>
";
我将preg_match_all用于正则表达式函数。
当我将$ string放入preg_match_all时,它将显示
警告:preg_match()[function.preg-match]:/home/document/public_html/test.php中第10行的未知修饰符'string'
我猜是因为我在$ string中有修饰符(/)。
我该如何解决?
实际代码
$string = "
///<summary
///aaa
///</summary>
";
$pattern = "/\/\/\/<summary>\/\/\/.*\/\/\/</summary";
preg_match($pattern,$a,$match);
您不必使用/
作为分隔符。 所以试试这个:
$pattern = '~///<summary>\s*///.*///</summary>~s';
使用preg_match_all
做起来会更容易
/\/\/\/.*/
代替。 这将匹配所有以///
开头的行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.