我正在使用amazon api(s)做一些工作,并在PHP查询中创建新文档时遇到了问题。我使用的是版本0.9.5
var_dump($innerHTML);
$php_query=\phpQuery::newDocument("<root>".$innerHTML."</root>");
var_dump($php_query->html());
给出读数:
string '<TotalOffers>2</TotalOffers><TotalOfferPages>1</TotalOfferPages> <MoreOffersUrl>https://www.amazon.co.uk/gp/offer-listing/B01KI13K0W%3FSubscriptionId%3DAKIAICCWYPWR3A76YQDQ%26tag%3D8496-5230-2708%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB01KI13K0W</MoreOffersUrl><Offer>
<Merchant>
<Name>Amazon.co.uk</Name>
</Merchant>
<OfferAttributes>
<Condition>New</Condition>
</OfferAttributes>
<OfferListing>
<OfferListingId>ZUHqmK4tgaBMBcOsWWSBV%2B%2FwXbnd%2BSYg58EFdjcH93Ayh%2FnSp741DyflKxdwL7w7k4O7nJ9zTBkxRNymmCq%2BNtgwHMXrFlFZRtfv0VL%2BBm8%3D</OfferListingId>
<Price>
<Amount>21999</Amount>
<CurrencyCode>GBP</CurrencyCode>
<FormattedPrice>£219.99</FormattedPrice>
</Price>
<Availability>Usually dispatched within 24 hours</Availability>
<AvailabilityAttributes>
<AvailabilityType>now</AvailabilityType>
<MinimumHours>0</MinimumHours>
<MaximumHours>0</MaximumHours>
</AvailabilityAttributes>
<IsEligibleForSuperSaverShipp'... (length=2055)
和...
string '<root><totaloffers>2</totaloffers><totalofferpages>1</totalofferpages><moreoffersurl>https://www.amazon.co.uk/gp/offer-listing/B01KI13K0W%3FSubscriptionId%3DAKIAICCWYPWR3A76YQDQ%26tag%3D8496-5230-2708%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12734%26creativeASIN%3DB01KI13K0W</moreoffersurl><offer><merchant><name>Amazon.co.uk</name></merchant><offerattributes><condition>New</condition></offerattributes><offerlisting><offerlistingid>ZUHqmK4tgaBMBcOsWWSBV%2B%2FwXbnd%2BSYg58EFdjcH93Ayh%2FnSp741DyflKxdwL7w7k4O7nJ9zTBkxRNymmCq%2BNtgwHMXrFlFZRtfv0VL%2BBm8%3D</offerlistingid><price><amount>21999</amount><currencycode>GBP</currencycode><formattedprice>£219.99</formattedprice></price><availability>Usually dispatched within 24 hours</availability><availabilityattributes><availabilitytype>now</availabilitytype><minimumhours>0</minimumhours><maximumhours>0</maximumhours></availabilityattributes><iseligibleforsupersavershipping>1</iseligibleforsupersavershipping><iseligibleforprime>1</iseligibleforprime></offerlisting>'... (length=1846)
正如您所见,标签大写已丢失。 这是PHPquery的默认行为,如果有,是否有任何方法可以维护标记大小写?
\ phpQuery :: newDocument在没有<root>
标签的情况下仍然这样做。
(请注意,这个问题的目的纯粹是关于在使用\ phpQuery :: newDocument时丢失大写字母的标签而不是在此上下文中使用PHPquery的功效)
感谢。
非常感谢帮助解决这个问题:)。
编辑:回答(感谢您的帮助!)\phpQuery::newDocument()
不区分大小写,应使用\phpQuery::newDocumentXML()
代替维护案例
答案 0 :(得分:0)
变化:
var_dump($innerHTML);
$php_query=\phpQuery::newDocument("<root>".$innerHTML."</root>");
var_dump($php_query->html());
为:
var_dump($innerHTML);
$php_query=\phpQuery::newDocumentXML("<root>".$innerHTML."</root>");
var_dump($php_query->html());
由于HTML对其标记名称不区分大小写,而XML则不区分大小写。因此\phpQuery::newDocument()
不区分大小写,并且不保持标记名称的大小写。而\phpQuery::newDocumentXML()
应该用来代替标记名称的大小写。