Euro sign

Dec 8, 2010 at 2:22 PM

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!

Dec 9, 2010 at 12:16 AM

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

Oct 12, 2011 at 10:22 PM

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().

Nov 17, 2011 at 11:55 AM

Hi,

Could you give an example how to fix it? I removed the utf8_encode in Section.php. But how further??

Thanx

Jun 5, 2012 at 11:07 AM

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.

Jan 7, 2014 at 6:30 AM
Got the same problem and tried the code of Eclectic.

It didn't worked for me and so i modified it a little bit ...

I added this line:
 $text = str_replace("E_U_R_O", "€" ,$text); 
On the same position and in my Text i use now E_U_R_O when i want to create a € sign in my word document.

Poor i know, but it works and maybe its a solution for someone else.
Mar 20, 2014 at 5:21 AM
The latest version of PHPWord can add utf8 character.