0

I am working with phpOffice/phpword document download. When I pass the content to the document download the content is like this,

<p>& operation check</p><p> < operation check</p><p> > operation check</p>

I want to change special character and content like,

<p> &amp; operation check</p> <p> &lt; operation check</p> <p> &gt; operation check</p>

I have done;

$textContent = strip_tags($content);
$content = htmlspecialchars($textContent);

The issue for the above I can replace html entities for the special characters, but I remove the html other tags and pass to document creation. then content style missing because only send the text content.

I have check the php - tidy. but not worked properly. can someone explain way to implement above operation.

user2552863
  • 483
  • 3
  • 10
  • 18
  • Explain logic behind why only some of `>` and `<` must be encoded? If text is `< a> < bold < i`, then what will be encoded and why? – Justinas Jan 22 '21 at 09:09
  • html tag no neet to comvert, assume some one add paragraph with special characters then only those special characters should convert to html entities, Here I have given only 3 &, <, > like this. I want to get a full html with html entities. this is for word file creation. – user2552863 Jan 22 '21 at 09:14

1 Answers1

1

This doesn't really make sense. The whole point of escaping characters in HTML is to do it before you add the tags. Something like this:

$content = "<p>" . htmlspecialchars("& operation check") . "</p><p>" . htmlspecialchars("< operation check") . "</p>";

If the data you have is already not escaped, then that data is broken, and shouldn't be used. You'll need to go back one step, and find out where you getting the data from and why is it broken, and get the data before it is broken.

RoToRa
  • 37,635
  • 12
  • 69
  • 105