0

我正在使用一个新框架,OctoberCMS,它有一个用于将页面与树枝链接的系统。这是它如何工作的示例

<a href="{{ '/about-us'|app }}">About Us</a>

我有一个巨大的表格,在单元格内有大量链接,需要将链接格式更改为符合 october 的格式。

这是表格单元格中的示例链接:

<a href="/assets/Lecture%20Documents/MBCS/MBS%20Class%20Review.doc">Lecture Notes</a>

这是它必须遵循的格式

<a href=
"/assets/<...long_path_to_file...>"> </a>

<a href=
"{{ 'assets/<...long_path_to_file...>' |theme }}"> </a>
4

1 回答 1

0

这个正则表达式应该适合你:

匹配:

/href=("|')(.*)("|')/ig 

并替换为

'href="{{ \'$2\'|theme }}"'

在 javascript 中,这看起来像:

var a = // get anchor tag
a.replace(/href=("|')(.*)("|')/ig, 'href="{{ \'$2\'|theme }}"');

在 php 中:

$htmlString = // get html string
$newHtml = preg_replace('/href=("|')(.*)("|')/ig', 'href="{{ \'$2\'|theme }}"', $htmlString);
于 2014-08-10T05:25:20.610 回答