Php 理解preg_替换的困难

Php 理解preg_替换的困难,php,preg-replace,Php,Preg Replace,目前,我正在为我的一个WordPress网站使用一个小型搜索和替换代码段: if ( ! function_exists( 'cor_remove_personal_options' ) ) { function cor_remove_personal_options( $subject ) { $pattern = '#<h3>Personal Options</h3>.+?/table>#s'; $subject = preg_replace

目前,我正在为我的一个WordPress网站使用一个小型搜索和替换代码段:

if ( ! function_exists( 'cor_remove_personal_options' ) ) {
  function cor_remove_personal_options( $subject ) {
    $pattern = '#<h3>Personal Options</h3>.+?/table>#s';
    $subject = preg_replace( $pattern, '', $subject, 1 );
    return $subject;
  }

  function cor_profile_subject_start() {
    ob_start( 'cor_remove_personal_options' );
  }

  function cor_profile_subject_end() {
    ob_end_flush();
  }
}
add_action( 'admin_head-profile.php', 'cor_profile_subject_start' );
add_action( 'admin_footer-profile.php', 'cor_profile_subject_end' );
如果(!function_存在('cor_remove_personal_options')){
功能相关删除个人选项($subject){
$pattern='#个人选项+?/table>#s';
$subject=preg_replace($pattern,,$subject,1);
返回$subject;
}
函数cor_profile_subject_start(){
ob_start(‘cor_remove_personal_options’);
}
函数cor_profile_subject_end(){
ob_end_flush();
}
}
添加动作('admin\u head-profile.php','cor\u profile\u subject\u start');
添加动作('admin\u footer-profile.php'、'cor\u profile\u subject\u end');
由于使用了
preg#u replace
相对较新,我想知道开始和结束号码符号
的确切功能


我想知道是否有人可以向我解释这一点?

这些歌声决定了替换模式的开始和结束。“s”是一个修饰符

您可以使用/作为开头和结尾字符或#。如果使用#,则斜杠不会被视为特殊字符,因此对斜杠字符进行转义也是有效的:

'/<h3>Personal Options<\/h3>.+?\/table>/s'
'/Personal Options.+?\/table>/s'

/s或#s表示修饰符,告诉PHP正则表达式中的任何点都将作为任何字符计算,包括新行。

谢谢。现在我对修饰符的功能有些了解。关于数字符号,你能告诉我它们确切的使用时间吗?我的意思是,我过去使用过
preg\u replace
,但没有它们,现在很难看到这段代码与以前的任何代码片段之间的差异。