我正在创建一个将旧网站迁移到joomla的脚本。 在我的旧网站上,所有php脚本都在utf8中。导入脚本也是。
要创建我这样做的文章:
$article = JTable::getInstance('content');
$article->title = $titre;
$article->alias = $alias;
$article->introtext = $contenu;
$article->catid = $idcat;
$article->created = JFactory::getDate()->toSQL();;
$article->created_by_alias = 'Import';
$article->state = 1;
$article->access = 1;
$article->metadesc = $description;
$article->metadata = '{"page_title":"'.$titre.'","author":"","robots":""}';
$article->language = '*';
if (!$article->check())
print $article->getError();
if (!$article->store(TRUE))
print $article->getError();
之后一切都很好,但我有第二次传球:
$query = $db->getQuery(true);
$query->select("id,introtext");
$query->from("#__content");
$query->where("1");
$db->setQuery((string) $query);
$messages = $db->loadObjectList();
foreach($messages as $page)
{
$idarticle=$page->id;
$dom = new DOMDocument;
@$dom->loadHTML(utf8_decode($page->introtext));
...
$fields = array("introtext=".$db->quote(utf8_encode($dom->saveHTML())));
$conditions = array("id='$idarticle'");
$query->update('#__content')->set($fields)->where($conditions);
$db->setQuery($query);
$result = $db->execute();
}
我尝试使用或不使用utf8_decode
/ utf8_encode
并且它是相同的:某些字符替换为?
,例如’
但重音字符很好。
答案 0 :(得分:1)
我找到了一个解决方案,不确定它是否会导致问题: 在文章创建之前,通过这种方式转换特殊字符:
public int onStartCommand(Intent intent, int flags, int startId) {
if (null == intent || null == intent.getAction ()) {
String source = null == intent ? "intent" : "action";
Log.e (TAG, source + " was null, flags=" + flags + " bits=" + Integer.toBinaryString (flags));
return START_REDELIVER_INTENT;
}
Gson gson = new Gson();
String json = intent.getStringExtra("stations");
stations = gson.fromJson(json,new TypeToken<List<StationViewModel>>(){}.getType());
setProximityAlert(addLocation(locationList));