亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

正則表達式獲取 MTOM 二進制 PDF 內容

正則表達式獲取 MTOM 二進制 PDF 內容

PHP
拉莫斯之舞 2023-04-21 13:34:25
我正在嘗試使用 SoapClient 的擴展類獲取 MTOM 二進制內容(這是一個 PDF)。這是參考類:https://github.com/debuss/MTOMSoapClient/blob/master/MTOMSoapClient.php因此,如果您看一下課程,您會看到我收到了一個響應,然后我使用正則表達式來獲取它的特定部分。這是我得到的全部回復。整個反應HTTP/1.1 200 OKDate: ...Server: .....Set-Cookie: ....; Path=/; HttpOnlySet-Cookie: ...; Path=/; HttpOnlyContent-Type: multipart/related; type="application/xop+xml"; boundary="uuid:0f7fa750-c317-4039-897a-a90685b00d29"; start="<...>"; start-info="text/xml"Keep-Alive: timeout=5, max=99Connection: Keep-AliveTransfer-Encoding: chunked--uuid:0f7fa750-c317-4039-897a-a90685b00d29Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";Content-Transfer-Encoding: binaryContent-ID: <[email protected]><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:downloadAttachResponse xmlns:ns2="http://..../"><return><errStr></errStr><result>0</result><contentFile><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:[email protected]"/></contentFile></return></ns2:downloadAttachResponse></soap:Body></soap:Envelope>--uuid:0f7fa750-c317-4039-897a-a90685b00d29Content-Type: application/octet-streamContent-Transfer-Encoding: binaryContent-ID: <[email protected]>%PDF-1.4...   LOTS OF BINARY CODE HERE FOR THE PDF--uuid:0f7fa750-c317-4039-897a-a90685b00d29--"響應<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">   <soap:Body>      <ns2:downloadAttachResponse xmlns:ns2="http://.../">         <return>            <errStr/>            <result>0</result>            <contentFile>               <xop:Include href="cid:[email protected]" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>            </contentFile>         </return>      </ns2:downloadAttachResponse>   </soap:Body></soap:Envelope>使用類的代碼,我在二進制數組上得到一個錯誤,該數組基本上是空的,因為正則表達式沒有獲取 pdf 內容。這是具體部分:那么,如何使用正則表達式獲取 PDF 二進制內容呢?
查看完整描述

1 回答

?
桃花長相依

TA貢獻1860條經驗 獲得超8個贊

在示例數據中,Content-ID: 部分以>

Content-ID: <[email protected]>

在您使用的模式中,這部分$cid.'[\s\S].+?>至少需要一個字符,[\s\S]后跟任何非貪婪字符的 1+ 倍.+?,這意味著在>

但在示例數據中,它們之間沒有字符。

您可以更新代碼以使用

preg_match('/Content-ID:[\s\S].+?'.$cid.'[\s\S]*?>([\s\S]*?)--uuid/', $response, $binary);

正則表達式演示

如果數據的結構總是這樣,您可以稍微優化一下模式:

Content-ID:\h+<[email protected]>\R\s*((?:(?!--uuid).*\R)*)--uuid

正則表達式演示


查看完整回答
反對 回復 2023-04-21
  • 1 回答
  • 0 關注
  • 118 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號