Using Drupal's admin I added to an existing content type a new text field with the machine name field_note.

When fetching the field in my code I want to check if $field_name == 'field_note' but it never does. When printing the value of $field_name I get field_note (should match).

Anyway, after a long process and looking at the hex values of both strings I found out that $field_name has 3 additional control characters at its end - the LRM (left to right mark). My workaround for this was using the following code:

$field_name=preg_replace('/\p{C}+/u', "", $field_name);

This works well, but I really want to understand why this happened? I have dozens of fields and only now this started happening with new fields.

A really big clue might be a recent upgrade from Drupal 7.23 to 7.63, but checking the database and field table they all remained with the same encoding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.