duanjiagu0655 2019-05-07 09:58
浏览 213

如何用新行替换XML格式的所有HTML换行符(<br>)?

I want to upload item description in the online shopping API. So that,I would like to replace all instances of <br> with newlines in xml. But I try to using below coding was does't work. Just this coding got problem, other coding no problem.

$product_short_description = str_replace("#<br\s*/?>#i", "
", $product_short_description);

The requirement of below html details element can support html format, the code is shown in below:

<htmlDetail>$product_short_description</htmlDetail>

Below is my all coding:

 <?php


include '../db_config/db_conn.php';

$sql = 'SELECT c1.entity_id AS product_id, c1.sku, c2.value AS prdNm, 
c3.value AS product_price, 
c5.value AS category_name, c6.value AS weight, c7.value AS image, c8.value 
AS description, 
c9.value AS price,c11.value AS shipment_type,c12.value AS 
warranty,c13.value AS short_description
FROM catalog_product_entity c1
LEFT JOIN catalog_product_entity_varchar c2 ON c1.entity_id=c2.entity_id 
AND c2.attribute_id=71
LEFT JOIN catalog_product_entity_decimal c3 ON c1.entity_id=c3.entity_id 
AND c3.attribute_id=75
LEFT JOIN catalog_category_product c4 ON c1.entity_id=c4.product_id
LEFT JOIN catalog_category_entity_varchar c5 ON 
c5.entity_id=c4.category_id AND c5.attribute_id=41
LEFT JOIN catalog_product_entity_decimal c6 ON c1.entity_id=c6.entity_id 
AND c6.attribute_id=80
LEFT JOIN catalog_product_entity_varchar c7 ON c1.entity_id=c7.entity_id 
 AND c7.attribute_id=85
LEFT JOIN catalog_product_entity_text c8 ON c1.entity_id=c8.entity_id AND 
c8.attribute_id=72
LEFT JOIN catalog_product_entity_decimal c9 ON c1.entity_id=c9.entity_id 
AND c9.attribute_id=75
LEFT JOIN catalog_product_entity_int c11 ON c1.entity_id=c11.entity_id AND 
c11.attribute_id=127
LEFT JOIN catalog_product_entity_int c12 ON c1.entity_id=c12.entity_id AND 
c12.attribute_id=154
LEFT JOIN catalog_product_entity_text c13 ON c1.entity_id=c13.entity_id 
AND c13.attribute_id=73
WHERE c1.entity_id = 200

';
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$product_id = $row['product_id'];
$product_sku = $row['sku'];
$product_name = $row['prdNm'];
$product_price = $row['product_price'];
$product_category_name = $row['category_name'];
$product_weight = $row['weight'];
$product_image = $row['image'];
$product_description = $row['description'];
$product_price = $row['price'];
$product_shipment_type = $row['shipment_type'];
$product_warranty = $row['warranty'];
$product_short_description = $row['short_description'];

}

/I'm stuck in here/
$product_short_description = str_replace("#<br\s*/?>#i", "
", $product_short_description);


$curl = curl_init();


curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.11street.my/rest/prodservices/product",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "<?xml version=\"1.0\" encoding=\"UTF-8\" 
standalone=\"yes\"?>
<Product>
<selMthdCd>01</selMthdCd>
<dispCtgrNo>4932</dispCtgrNo>
<prdTypCd>01</prdTypCd>
 <prdNm>$product_name</prdNm>
 <prdStatCd>01</prdStatCd>
 <prdWght>$product_weight</prdWght>
 <minorSelCnYn>Y</minorSelCnYn>
 <prdImage01>$product_image</prdImage01>
 <htmlDetail>$product_short_description</htmlDetail>

 </Product>",
 CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/xml",
"openapikey: asdfsdafq2e212ewsadfd",
 ),
 ));

 $response = curl_exec($curl);
 $err = curl_error($curl);

 curl_close($curl);

 echo $response;

It show me the error:

Product registration failed Detail Description is required.500

If coding is successed, will show me:

The product has been successfully registered. Product No: 68931722200

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向