我正在循環瀏覽一些帶有嵌入式文獻參考的文本。其中一些是DOI號,我需要將它們聯繫起來。使用preg_replace鏈接DOI
示例文本:
<div>Interesting article here: doi:10.1203/00006450-199305000-00005</div>
我試過到目前爲止:
$html = preg_replace("\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?![\"&\'<>])[[:graph:]])+)\b", "<a href='https://doi.org/\\0' target='_new'>doi:\\0</a>",$html);
這將返回一個空字符串。
我期待:
<div>Interesting article here: <a href='https://doi.org/10.1203/00006450-199305000-00005' target='_new'>doi:10.1203/00006450-199305000-00005</a></div>
我要去哪裏錯了?
編輯2018-01-30:更新的DOI解析器根據卡特琳的答案在下面。
謝謝,將用新的解析器更新我的問題。 – 2018-01-30 18:48:26