【问题标题】:PHP preg_match get string inside double quotes for WordPress syntaxPHP preg_match 获取 WordPress 语法双引号内的字符串
【发布时间】:2014-02-26 04:21:49
【问题描述】:

我在我的 WordPress 语法代码高亮中使用了 preg_match_all 单引号 ',它正在工作

preg_match_all("/'(.*?)'/",$content,$matches);

但是当我在这段代码中使用双引号 " 时,它不起作用

preg_match_all('/"(.*?)"/',$content,$matches);

有没有简单的方法来修复代码?

--编辑--

我正在使用此代码制作我自己的 wordpress 语法高亮代码插件

function myHighlightSyntaxCode($content ) 
{
   global $post;
   $content= $post->post_content;                          
   $content=reformatText($content);
   return $content;
}
function reformatText($content){

   preg_match_all("/'(.*?)'/",$content,$matches);
   /*
     this is the part of my code for content inside quote
   */

}
add_filter( 'the_content', 'myHighlightSyntaxCode');

【问题讨论】:

  • 您能否向我们展示$content 的示例以及您希望在$matches 中找到什么?
  • 是的,你可以在我的博客上看到:) blog.imammubin.com/…

标签: php wordpress preg-replace preg-match-all


【解决方案1】:

这样做会否定匹配项中的引号

preg_match_all('/"([^"]*)"/',$content,$matches);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多