我试图在我的代码中使用PHP中的正则表达式获取注释字符串.
假设我有以下字符串.
$string = "
///<summary>
///test
///</summary>
";
Run Code Online (Sandbox Code Playgroud)
我使用preg_match_all作为正则表达式函数.
当我把$ string放到preg_match_all时,它显示出来
警告:preg_match()[function.preg-match]:第10行/home/document/public_html/test.php中的未知修饰符'string'
我想这是因为我在$ string中有修饰符(/).
我该如何解决这个问题?
实际代码
$string = "
///<summary
///aaa
///</summary>
";
$pattern = "/\/\/\/<summary>\/\/\/.*\/\/\/</summary";
preg_match($pattern,$a,$match);
Run Code Online (Sandbox Code Playgroud)
您不必使用/分隔符.试试这个:
$pattern = '~///<summary>\s*///.*///</summary>~s';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
185 次 |
| 最近记录: |