2016-03-04 71 views
0

我對這個主題完全陌生。我創建了一個Feed來顯示我們的產品。但我無法弄清楚如何限制要在名稱標籤中顯示的字符數。XML輸出提要

$product_title = $productDescription[2]['name'] ? html_entity_decode($productDescription[2]['name'], ENT_QUOTES, 'UTF-8') : ''; 
         $output .= '<item_name ><![CDATA['.$product_title.']]></item_name>'."\n"; 
         $description = html_entity_decode($productDescription[2]['description'], ENT_QUOTES, 'UTF-8'); 

回答

0

也許我不完全理解的問題,但如果你想只是爲了PRODUCT_TITLE限制到ITEM_NAME您可以使用此代碼

$desired_length = 100; // or some other value 
$product_title = $productDescription[2]['name'] ? html_entity_decode($productDescription[2]['name'], ENT_QUOTES, 'UTF-8') : ''; 
$product_title = substr($product_title, 0, $desired_length); 
$output .= '<item_name ><![CDATA['.$product_title.']]></item_name>'."\n"; 
$description = html_entity_decode($productDescription[2]['description'], ENT_QUOTES, 'UTF-8'); 
+0

謝謝你,就像一個魅力。 – Chrissy1994

+1

如果此答案適用於您,您是否可以將此問題標記爲已接受? –