现在使用PHP几年,今天遇到一个奇怪的错误。使用MySQL生成XML提要。以下内容在输出
中继续发生<title>title</title>
<link>link</link>
<description>descriptiondescription>
使用print或echo时,某些Feed输出会遗漏标签,这是代码。
print "<description>";
$desc = strip_tags($rowx['meta_description']);
$desc = htmlspecialchars($desc);
$desc = urlencode($desc);
$desc = str_replace('%95', '', $desc);
$desc = str_replace('%92', '', $desc);
$desc = str_replace('%A3', '', $desc);
$desc = urldecode($desc);
print preg_replace( "/\r|\n/", "", $desc );
print "</description>";
print "\n";
输出的另一个例子
<g:condition>new</g:condition>
<g:brand>SALTO</g:brand>
<g:color></g:color>
g:size></g:size>
<g:payment_accepted>Visa</g:payment_accepted>
上面输出的代码
print "<g:condition>new</g:condition>";
// print "\n";
// brand
print "<g:brand>";
$result_brand = mysql_query("SELECT value FROM cscart_product_features_values WHERE feature_id = '80' AND product_id = '$product_id'");
$row_brand = mysql_fetch_row($result_brand);
print $row_brand[0];
print "</g:brand>";
// print "\n";
// color
print "<g:color>";
$result_color = mysql_query("SELECT cscart_product_feature_variant_descriptions.variant FROM cscart_product_feature_variant_descriptions, cscart_product_features_values WHERE cscart_product_feature_variant_descriptions.variant_id = cscart_product_features_values.variant_id AND cscart_product_features_values.feature_id = '19' AND product_id = '$product_id'");
$row_color = mysql_fetch_row($result_color);
print $row_color[0];
print "</g:color>";
// print "\n";
// size
print "<g:size>";
$result_size = mysql_query("SELECT cscart_product_feature_variant_descriptions.variant FROM cscart_product_feature_variant_descriptions, cscart_product_features_values WHERE cscart_product_feature_variant_descriptions.variant_id = cscart_product_features_values.variant_id AND cscart_product_features_values.feature_id = '25' AND product_id = '$product_id'");
$row_size = mysql_fetch_row($result_size);
print $row_size[0];
print "</g:size>";
// print "\n";
print "<g:payment_accepted>Visa</g:payment_accepted>";
答案 0 :(得分:0)
我使用“test”一词代替$ rowx ['meta_description']来测试代码并且它工作了......你能否为失败案例提供当前的'meta_description'数据?