Open kalibano opened 3 years ago
You're adding raw HTML, so you should escape your input: B&B
should be B&B
. This can be done using htmlspecialchars
(but you'll lose the ability to add HTML elements, as those will be escaped, too; however, "B&B" as a word is invalid HTML anyway).
It is stored as B&B
in database. And yes i can not use htmlspecialchars as it does escape html elements too so what should do now?
I think you're correct that B&B
causes malformed output (it is stored as B&B
in word/document.xml
).
A quick and dirty hack would be to escape &
another time using
$content = str_replace('&', '&', $content);
yes replaced the &
with &
but then &npbs;
causes the issue. then i replaced &npbs;
with  
also str_replace('’', "'", $html); $html = str_replace('“', '"', $html); $html = str_replace('”', '"', $html);
and it is working fine now. But I am not sure how it will response for other special characters. I think it would be helpful if package itself handle all special characters
&npbs;
should be
, an invalid entity will cause an error. And of course this is only a dirty hack, not a solution. And please, next time show your exact content (or a MWE that causes the issue), as now we have to guess about what triggers the issue, apart from 'B&B'.
sorry it was writing mistake yes replaced with  
.And I gave example 'B&B' which was the part of large content. I don't have static content.every time user enter own content. So For new content it is again creating corrupted file :( and once again needed to search for character that is causing issue.
any other solution?
Still having this issue, using setValue()
but fortunately using &
works
You need to set output escaping. See discussion at: https://github.com/PHPOffice/PHPWord/issues/2524#issuecomment-1847981808
I think you're correct that
B&B
causes malformed output (it is stored asB&B
inword/document.xml
).A quick and dirty hack would be to escape
&
another time using$content = str_replace('&', '&', $content);
Thanks.
content has ampersand sign 'B&B', which is causing file corrupt. I have tried solutions given here on github but doesn't work in my case.anyone have any idea how to correct this issue?its really urgent I will be grateful for help
Steps to Reproduce
Please provide a code sample that reproduces the issue.
Current Behavior
creating corrupt file