2015-11-19 30 views
0

我正在構建一個必須填寫docx文檔的Web應用程序。我正在使用PHPWord提供的TemplateProcessor,它在文檔上呈現特定的鉤子並用給定的字符串替換它。我遇到的問題是當字符串「&」正在呈現 - 由於缺少';',文檔被損壞。使用PHPWord填寫docx文檔時'Escape'&'

,我用它來清理字符串的函數是

$string = trim(html_entity_decode($string)); 
$string = strip_tags($string); 
$string = trim(preg_replace('/\s+/', ' ', $string)); 

有沒有人有一個想法,我怎麼能逃脫ampersant符號,以便該文件將不會受到損壞?

回答

2

肯定:看this HTML Entity chart

$str = preg_replace('/&/', '&', $str); 

你的情況然而,最好使用htmlspecialchars添加此行:

$str = htmlspecialchars($str); 
+0

謝謝這已經固定我的問題! –

+0

不客氣!另請參閱我的更新。 – Kenney

相關問題