1

我正在使用ebay api将项目提取到我的网站,callname=GetSingleItem一切正常。

请查看我用来获取项目详细信息的以下代码段

    $res = $api -> get ( "http://open.api.ebay.com/shopping?"
                        . "callname=GetSingleItem&"
                        . 
   "IncludeSelector=Description,ItemSpecifics,Details&"
                        . "ItemID=" . $listing -> platform_key . '&'
                        . "appid=$ebayAppId&"
                        . "version=".$version ) ;

                    $xml = simplexml_load_string ( $res -> getBody () ) ;
                    $json = json_encode ( $xml ) ;
                    $jsonResult = json_decode ( $json , TRUE ) ;

然后我通过下面的代码段获取它的详细信息

     $ebayItemArray[ "description" ] = ( $jsonResult[ "Item" ][ "Description" ] 
   )

请注意,以上代码段只是示例代码

所以我通过下面的代码段使用这个描述Laravel blade.php

      <div class=container text-left">
                            {!!$ebayItemArray[ "description" ]!!}
                        </div>

因此,对于某些产品,这很有效,没有任何错误,但是对于某些产品,当我尝试显示描述时,它会破坏我的布局样式,如下所示

剪辑 01 剪辑 02

当我从刀片文件中删除描述变量时,一切正常

4

1 回答 1

1

根据文档:

如果使用了 Description 值,则返回完整的描述,以及卖家在列表中使用的所有 HTML、XML 或 CSS 标记(如果有)。要仅查看列表描述的实际文本(无标记标签),应使用 TextDescription 值。

因此,可能是额外的 CSS 破坏了您的页面结构。

你有选择

  1. 将描述值转换为纯文本
// Not tested...
$description = $jsonResult[ "Item" ][ "Description" ];
$doc = new DOMDocument();
$doc->loadHTML($description); // Load as HTML
removeElementsByTagName('style', $doc); // Remove the <style> Tag
$description = strip_tags($doc->textContent); // To plain Text
$ebayItemArray[ "description" ] = $description;
  1. 利用IncludeSelector=TextDescription
$res = $api -> get ( "http://open.api.ebay.com/shopping?"
                        . "callname=GetSingleItem&"
                        . 
   "IncludeSelector=TextDescription,ItemSpecifics,Details&"
                        . "ItemID=" . $listing -> platform_key . '&'
                        . "appid=$ebayAppId&"
                        . "version=".$version ) ;
  1. 在插入描述的地方使用 iFrame
<iframe 
  title="Description" 
  srcdoc="{!!$ebayItemArray[ "description" ]!!}"
  width="300px" height="300px"
></iframe>

使用 iFrame,您还需要自动调整 iFrame 的高度。

于 2019-11-06T11:59:18.797 回答