PHP将GitHub标记图像URL转换为已发布页面URL

PHP将GitHub标记图像URL转换为已发布页面URL,php,image,preg-replace,markdown,Php,Image,Preg Replace,Markdown,我需要通过PHP转换文本块中的所有标记URL,如: https://github.com/username/myrepo/blob/master/images/subdir/voyage-dans-la-lune.jpg 通过GH页面发布时的URL,例如 https://username.github.com/myrepo/images/subdir/voyage-dans-la-lune.jpg 我的preg_替换模式失败: $replace=preg\u replace('\'https:/

我需要通过PHP转换文本块中的所有标记URL,如:

https://github.com/username/myrepo/blob/master/images/subdir/voyage-dans-la-lune.jpg

通过GH页面发布时的URL,例如

https://username.github.com/myrepo/images/subdir/voyage-dans-la-lune.jpg

我的preg_替换模式失败:

$replace=preg\u replace('\'https://github.com/([a-zA-Z0-9\\-]+)/([a-zA-Z0-9\\-]+)/blob/master/images\'',https://\\1.github.io/\\2/images',$content,-1,$rcount)


我希望我忽略了一些琐碎的东西。

你能清楚地写出你的输入字符串和期望的输出吗?这段代码运行良好(尽管使用了无用的反斜杠和愚蠢的分隔符选择)。问题是什么?请参阅:感谢您提供的更清洁的图案;我的错误是在处理函数的返回值时出错。它正在工作