Drupal node_save and special characters
i'm trying to create nodes and taxonomy terms through a custom php script by using the node_save() function.
I'm working on drupal 6.
It's working well (thanks to previous questions on stackoverflow) except for accented letters.
Indeed, when a title or a taxonomy term contain "é", "è" or "à", the sentence is cut before those special characters.
For example, a title like that: "Bonjour les éléphants" will cre开发者_JS百科ate a node with "Bonjour les " as title.
I don't know if it's linked to my database or if i have to use a special encoding in php (iconv() blabla)
The fact is, for drupal titles, i can not use html encoding (for example: é is é in html) because drupal will render é and not é...
When i create a taxonomy or a title manually, i have no problems and the accented letter is saved in the database as "é".
Soo if you can help me to create terms and title with accented letters, that will be great : )
Thank you !
This kind of looks like some sort of encoding/charset problem...
With Drupal, everything is encoded (and expected) in the UTF-8 charset.
Not sure it'll solve/fix your problem, but you should make sure that everything in your application is working with/in UTF-8 :
- Your PHP files, containing your source-code, should be in UTF-8
- There is probably some setting about that in your IDE/editor
- This will ensure that the strings you hard-code are in UTF-8 too
- When using some external data, before calling
node_save
on it, you must make sure it's in UTF-8- The
utf8_encode
function might help - Or maybe
mb_convert_encoding
, depending on the charset used by your input data.
- The
I've run into exactly that problem of strings cut before accented characters a couple of times, and, each time, making sure the strings were passed as UTF-8 solved it -- so maybe it'll work for you too ^^
In Eclipse you can change this as following:
Preferences > General > Workspaces, set "Text file encoding" to "Other : UTF-8".
精彩评论