[英]extract data from file_get_contents
我已使用 webex 數據在我的網站上顯示會議,但是在返回數據時遇到了問題。
$sitename = "sitename";
$username = "api@webex.com";
$password = "password!";
$XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$XML .="<serv:message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";
$XML .=" <header>";
$XML .=" <securityContext>";
$XML .=" <webExID>$username</webExID>";
$XML .=" <password>$password</password>";
$XML .=" <siteName>$sitename</siteName>";
$XML .=" </securityContext>";
$XML .=" </header>";
$XML .=" <body>";
$XML .=" <bodyContent xsi:type=\"java:com.webex.service.binding.meeting.GetjoinurlMeeting\">";
$XML .=" <meetingKey>1460755337</meetingKey>";
$XML .=" </bodyContent>";
$XML .=" </body>";
$XML .="</serv:message>";
$request = stream_context_create(array("http"=>array("method"=>"POST","header"=>"Content-Type:text/xml","content"=>$XML)));
$response = file_get_contents("https://$sitename.webex.com/WBXService/XMLService", true, $request);
實際 XML 響應 在通過 header 請求后,我得到如下響應
SUCCESSPRIMARYfalsefalseC!sco123falsefalseMeeting 13 jjb87@miami.edufalse1myemail@gmail.commyemail@gmail.comPERSONALmyemail@gmail.comVISITOR1097099526INVITE1467275084ENGLISHATTENDEE1truetruetruetruetruetruetruetruetruetruefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsetruetruetruefalsefalsetruefalsetruefalsefalsetruetruefalsefalsefalsetruefalsefalsetruefalsefalsefalsefalsefalsefalsefalsetruefalsefalsefalsetruefalsefalsefalsetruetruetrue07/10/2020 12:00:004GMT-08:00, Pacific (San Jose)20900rachel@modiht.comfalsefalse000falsefalsefalseCALLBACK50falsefalseUS+1-415-655-00011-844-621-3956falsefalseNO_REPEATtruerachel@modiht.comtruefalse0015falsefalsefalse0falsefalse146727508475c9ca6757090f047a57136a85ee09cbNOT_INPROGRESSfalsefalsefalse50223710221954770ec6374b4ace66655ed33b7bcf0a9ac61019001truehttps://api.webex.com/modiht/j.php?MTID=m32de914bf4153f200c60e1ad420376ed1467275084@api.webex.com1467275084@api.webex.com
所以我的問題是如何從響應中獲取最后一個1467275084@api.webex.com
請幫我解決這個問題。
好的,我在預賽中做到了,這是我問題的答案
$emails = getLastEmailFromString($response);
$arrEmail = implode("\n", $emails);
$lastEMail = end( $emails);
return $lastEMail;
function getLastEmailFromString($string){
preg_match_all("/[\._a-zA-Z0-9-]+@[\.api.webex.com-]+/i", $string, $matches);
return $matches[0];
}
file()
方法將結果作為數組返回,這可能更適合您的需求。
$response = file("https://$sitename.webex.com/WBXService/XMLService", true, $request);
$lastLine = $response[count($response)-1];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.