Related to this post for some reason customer's theme appears to be mishandling the single foot mark (') which most refer to as apostrophe and at the twig.engine stage is outputiting the html of

'

None of the other fields do this, just title. The theme is pulling core/themes/classy/templates/field/field--node--title.html.twig. In my troubleshooting today, switching to Bartik resolves the issue but I've never been able to debug what twig is doing.

Copying/pasting the right single quote mark from my Mac into the node title field gets past this issue.

With time running out I have added to my hook_entity_presave function something that should should work on paper:

$fullname = str_replace(chr(39), chr(146), $fullname);

But a 500 error is returned because MySQL is balking at this character.

Incorrect string value: '\x92Conne...' for column 'title' at row 1: 

In the variables we see the question character for a symbol that's not recognized. MySQL is encoding utf8mb3 (utf_general_ci). The docs for chr() suggest it can accept ascii, hex and Oct values. None of these work however.

Perhaps passing in the UTF-8 value? Online it suggests 0xE2 0x80 0x99 (e28099) as the hex but Drupal hangs trying that in the chr() function. I checked out Drupal's Unicode class but it doesn't seem to have an encode method, just decoding? I've been at this and need a reality check on this problem. thx, sam

Comments

johnpitcairn’s picture

Have you tried just using the character literals enclosed by " "?

$fullname = str_replace("'", "’", $fullname);

sam452’s picture

For this content_type a foot mark/apostrophe in the title field can only mean a right-single quote (or typographer apostrophe) and this gets past the issue.

Wish I knew what is causing this to occur only on the title field, thx, sam

Ankit.Gupta’s picture

You can check below article, may be helpful for you

https://stackoverflow.com/questions/2741091/replacing-character-in-php

sam452’s picture

is better than mine. This is helpful info, thx