phphtmlspecialchars

PHP simplexlsxgen issue displaying HTML special characters


I am exporting some data into an excel by using simplexlsxgen . My data has a value <<NEW>> and I am having a trouble displaying it.

In my code I prepared it in htmlspecialchars("<<NEW>>"), which will work if I want to display it in the browser page, but when it gets exported in an excel $xlsx->saveAs($fullFilePath) the data somehow will become &lt;&lt;NEW&gt;&gt;. If I simply prepare it as "<<NEW>>" nothing will be displayed.

SAMPLE CODE

$excelArr = [
    ['DOC', 'DOCDATE'],
    ['<<NEW>>', '05/01/2023']
];

$xlsx = $this->simplexlsxgen->fromArray($excelArr);
$xlsx->saveAs('/');

SAMPLE OUTPUT OF ABOVE

enter image description here

Since in $excelArr the value <<NEW>> is simply written as it is, it displays an empty cell when exported in excel. Due to this, as what I mentioned above, I tried to use htmlspecialchars("<<NEW>>") instead which I thought would work but it will display &lt;&lt;NEW&gt;&gt; in the excel cell.


Solution

  • Use raw strings to insert tags https://github.com/shuchkin/simplexlsxgen#raw-strings