|
|
Hello,
Does someone know how to insert a euro sign in PHPWord?
The dollar sign works fine, but the euro sign not (€).
I've been looking for an answer for hours, but I couldn't find one.
Thank you!
|
|
|
|
Maybe the ascii will work: chr(8364)
http://php.net/manual/en/function.chr.php
The problem is that this won't work if your font does not have a euro symbol, so use newer fonts in your docx.
http://www.cs.tut.fi/~jkorpela/html/euro.html
More information about ascii here:
http://en.wikipedia.org/wiki/ASCII
|
|
|
|
I have a solution but we have to change the source code of PHPWord.
The problem is the use of utf8_encode (for example in Section.php file).
public function addText($text, $styleFont = null, $styleParagraph = null) {
$givenText = utf8_encode($text);
$text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
utf8_encode() take an ISO-8859-1 encoded string as parameter. But euro sign exists in ISO-8859-15 but not in ISO-8859-1.
http://en.wikipedia.org/wiki/ISO/IEC_8859-15
If we send a ISO-8859-15, we have the ¤ sign by using utf8_encode() and not €.
The solution is to remove the utf8_encode() and use a utf8 encoded string as parameter of addText().
|
|
|
|
Hi,
Could you give an example how to fix it? I removed the utf8_encode in Section.php. But how further??
Thanx
|
|
|
|
Hi,
I've found another solution modifying the source code (adding a code line that implements the php function 'str_replace').
Go to the function 'addText' in the file that corresponds.
In my case (cause I'm creating a table), I added the code line in this function in: PHPWord\Section\Table\Cell.php
public function addText ($text, $styleFont = null, $styleParagraph = null)
{
$text = utf8_encode($text);
$text = str_replace(array("€","€"),"€",$text); // The line added
$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
$this->_elementCollection [] = $text;
return $text;
}
Notes: '€' is if the source is HTML
'€' is if the source is utf8_unicode
Depending on where
it is used, the 'addText'
function can be found in : Cell.php , Footer.php , Header.php , Section.php , TextRun.php .
Regards.
|
|