如何将<link />标记解析为正确的<a> tags?

时间:2016-12-01 15:05:07

标签: php typo3

I have textblocks which look something like this:

$message ='<div>Lorem ipsum dolor sit amet <link http://some/website.html _blank external-link-new-window "Opens external link in new window">here</link> Lorem <link foo@bar.com - mail "Opens window for sending email"><div>'

Now I need to parse those link tags to proper a tags in pure php. I've tried with regexes so far but didnt achieve much. I know these function exists in the typo3 core in this class right here: Link 有任何建议如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

Simply run it through the parsefunc_RTE, try this snippet:

 $message = ...
 $parseFuncConf = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];
 $messageHtml = $GLOBALS['TSFE']->cObj->parseFunc($message, $parseFuncConf);

答案 1 :(得分:0)

如果您将此消息输出到流体模板,您可以使用它。猜猜它应该解析链接。 在PHP中,您可以使用ContentObjectRenderer的函数,如下所示:https://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_frontend_1_1_content_object_1_1_content_object_renderer.html#a1f5083b23f8f4a6cb6c26a3f6807bb37