PHP正则表达式在md代码块的字符串中获取字符串


php regex to get string within string of md code block

我有这个字符串:

```yaml
project_id: 524
type:
  - content changes
  - code changes
production_urls:
  - http://produrl.net/special/page
database_tables:
  - content
  - articles
```

我需要得到yaml和' ' '之间的文本。所以新的字符串将以project_id...开始,以...articles

结束

用PHP获得新字符串的最有效方法是什么?

对于正则表达式,只需这样做:

<?php
$string = '```yaml
project_id: 524
type:
  - content changes
  - code changes
production_urls:
  - http://produrl.net/special/page
database_tables:
  - content
  - articles
```';
$string = preg_replace('#^```yaml(.*)```$#s', '$1', $string);
echo "<pre>".print_r($string, true)."</pre>";
?>