我正在嘗試使用 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
- 1 回答
- 0 關注
- 118 瀏覽
添加回答
舉報
0/150
提交
取消