我正在尝试为我创建一个实用程序,该实用程序可以将Word文档转换为干净的HTML,但停留在多行生成的清理标签上。如果有人想在线查看该工具,但我不希望此帖子被标记为垃圾邮件,我可以共享该链接。
我想使用php或javascript用一个标签替换
.. 和
... 。我使用过HTML Tidy。
function cleaning($string, $tidyConfig = null)
{
$out = array ();
$config = array (
'indent' => true,
'show-body-only' => false,
'clean' => true,
'output-xhtml' => true,
'preserve-entities' => true
);
if ($tidyConfig == null) {
$tidyConfig = &$config;
}
$tidy = new tidy ();
$out ['full'] = $tidy->repairString ( $string, $tidyConfig, 'UTF8' );
unset ( $tidy );
unset ( $tidyConfig );
$out ['body'] = preg_replace ( "/.*<body[^>]*>|<\/body>.*/si", "", $out ['full'] );
$out ['style'] = '<style type="text/css">' . preg_replace ( "/.*<style[^>]*>|<\/style>.*/si", "", $out ['full'] ) . '</style>';
return ($out);
}
答案 0 :(得分:1)
对于我来说,根据您的示例代码,您所期望的结果到底是什么也不十分清楚。
例如,您将以下内容准确地转换为什么,以及为什么将其转换为有效的HTML代码?
select (case when country in ('India','Portugal') then country else 'others' end) as country,
count(distinct customer_id) as customers
from table t
group by (case when country in ('India','Portugal') then country else 'others' end)
您可以使用<p>
<strong>Minify</strong> <strong>CSSis
all free</strong>
</p>
<p>
将strip_tags()
转换为以下示例:
strip_tags($text,'<p>')
或使用<p>
Minify CSSis
all free
</p>
<p>
:
strip_tags($text,'<strong>')
<strong>Minify</strong> <strong>CSSis
all free</strong>
和trim()
的组合可以将其清理成单行,例如:
str_replace()
强烈建议您更新您的问题,以确保清楚和最终结果。