This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Developer » Extract() returns garbage when result...

Extract() returns garbage when result contains special chars

Extract() returns garbage when result contains special chars

Monday 20 April 2015 8:33:10 am - 4 replies


I have written the following code


and $user value is equal to "Håmel". The above code should return "å". But instead it returns a garbage char (�). Please note that, if I echo out {$user} then it correctly displays "Håmel".


Would anyone please help me on this?


Thanks in advance.


Modified on Monday 20 April 2015 8:34:48 am by Rashidul Islam Rana

Monday 20 April 2015 12:31:18 pm

Hello Rashidul,

Welcome to the eZ Community!

I think you have found a bug in eZ Publish! big-smile.gif Emoticon

I did a bunch of testing and found I could solve the bug but it requires a kernel change which you should not do of course.

The problem is the code which powers the extract template operator uses the php function substr instead of mb_substr.

I did a bit of research and found this helpful thread discussing the topic in question:

I did testing and these two instances of substr should be replaced with mb_substr:

This one probably needs to be changed too:

I think this bug affects all of the extract based template operators. But this patch once submitted as PR should solve it without issues (since the kernel already sets mb_internal_encoding( 'utf-8' ) by default.

Would you be willing to submit a pull request to the ezpublish-legacy repository patch this bug?

Alternatively you could avoid the bug by creating a custom template operator.

Also you could override the kernel class within an extension (what I would do while waiting for your pull request to be merged) since it's a little faster than creating a custom template operator.

I hope this helps!


Wednesday 22 April 2015 1:08:00 pm

Hello Rashidul,

I took the time tonight (instead of sleeping) to build a pull request to solve this issue and other similar issues (within the context of other similar operators provided by the same underlying php class).

If you wish for these changes to be merged into the ezpublish repository please show your support by making a comment in the following pull request:

Here is the PR's issue ticket:

I hope this helps you and others!


Monday 27 April 2015 8:08:08 am

Hi Heath,


Thank you very much for your response. I can't appreciate your effort enough. Sorry for being late in reply. I was very busy. And Yeah, above changes does the trick.


Thanks again Man

Monday 27 April 2015 9:27:57 am

Hello Rashidul,

Your very welcome! I was happy to be able to help you address your problem.

Thank you for showing your support in the pull request!

I hope this can be reviewed further and merged quickly.

I'll post updates here as the PR progresses.



You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from