doubei2231 2016-06-02 09:07
浏览 147
已采纳

PHP / Markdown:需要匹配反引号内的代码块

I am creating a developers site with code views, but when they type code i need to it a certain way so in the php and can convert it to html a special way,

The markdown i need to be able to work with is

```codechanger
``php
<?php ?>
``
``c#
$foo = bar;
``
```

So once the first regex select code changer I then need to be able to select each code but i just need to know the regex to match everything inside there even if it is on multiple lines.

This is what i was trying to use

preg_match_all("/\`\`codechanger.*?^\`\`[^
]*/s", $text, $out);

Any questions feel free to ask.

  • 写回答

1条回答 默认 最新

  • duanche4578 2016-06-04 19:30
    关注

    If you want to get the text between a start and end point, you can do something like this: START .*? END

    ```codechanger(.*?)```
    

    When combined with the s flag like you have, that will give you everything in $1 between the starting and ending positions.

    Once you have the results you can do another preg_match_all to get the inner tags.

    Here is a demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?