[英]PHP - Drupal create node utf8 romanian characters
我有一個cronjob,每天都會創建一個新節點。 正文值為羅馬尼亞語,因此文本包含羅馬尼亞變音符號。
DB列均為utf8-general-ci。 (兩個表:我從drupal的字段主體表中獲取數據的表)。
我正在使用此代碼創建節點:
$new_node = new stdClass();
$new_node->type = 'quote_of_the_day';
node_object_prepare($new_node);
$new_node->language = 'ro';
$new_node->uid = USER_ID;
$new_node->title = $citat['titlu'];
$new_node->body['und'][0]['value'] = $citat['text'];
$new_node->body['und'][0]['format'] = 'full_html';
$new_node->body['und'][0]['safe_value'] = $citat['text'];
我的問題是羅馬尼亞字符被替換為一些奇怪的字符。 見圖片:
我在此節點類型上將multilingual設置為true。 當我編輯此腳本創建的節點時,語言設置正確。
我正在使用drupal 7.56。
關於如何正確進入人體和瀏覽器的任何想法?
編輯:我添加了所有@ M0ns1f說。 相同的輸出。
首先,您需要為HTML output
指定字符集..在頁面標題中添加:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
在PHP
可以使用(此行必須在代碼中位於第一行):
<?php header("Content-type: text/html; charset=utf-8");?>
那么您需要在網站的根目錄中寫入.htaccess
:
`# Set httpd charset to utf-8
AddDefaultCharset On
AddDefaultCharset utf-8`
將php charset設置為utf-8並設置mbstring(您可能需要安裝mbstring模塊)
php_value default_charset utf-8
php_value mbstring.internal_encoding utf-8
php_value mbstring.func_overload 7
然后嘗試添加mb_convert_encoding
函數
$new_node = new stdClass();
$new_node->type = 'quote_of_the_day';
node_object_prepare($new_node);
$new_node->language = 'ro';
$new_node->uid = USER_ID;
$new_node->title = $citat['titlu'];
$new_node->body['und'][0]['value'] = mb_convert_encoding($citat['text'], 'HTML-ENTITIES', 'UTF-8');
$new_node->body['und'][0]['format'] = 'full_html';
$new_node->body['und'][0]['safe_value'] = mb_convert_encoding($citat['text'], 'HTML-ENTITIES', 'UTF-8');
或將$citat['text']
更改為此
htmlentities(utf8_encode($citat['text']), 0, "UTF-8")
你試過了嗎 :
$new_node->body['und'][0]['value'] = mb_convert_encoding($citat['text'], 'HTML-ENTITIES', mb_detect_encoding($citat['text']));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.