【发布时间】:2021-03-24 21:30:22
【问题描述】:
如何从括号之间的链接中提取文本的链接文本:
例如:
$string = 'adorti sunt Montium primum [a href="https://..."]Link name[/a] divaricaturn sine spiramento ullo. post haec militares, [a href="https://..." class="ln-style-1"]blabla[/a].';
我需要得到:
$result = 'adorti sunt Montium primum Link name divaricaturn sine spiramento ullo. post haec militares, blabla.'
解决方案:
感谢@Slava Rozhnev,我找到了一种方法:
$result = str_replace('[/a]', '', preg_replace('/\[a.*?\]/', '', $string));
【问题讨论】:
-
Stack Overflow 不是代码编写服务,你应该知道这一点。您应该尝试自己编写代码。请阅读How to create a Minimal, Reproducible Example 和How do I ask a good question?。
-
是的,很抱歉,但我不会很好地掌握正则表达式。