简体   繁体   English

在 PHP 中从 SimpleXML 对象中检索值

[英]Retrieve value from SimpleXML object in PHP

$bbb = new BigBlueButton();

$recordingsParams = array(
    'meetingId' => '', 

);

// Now get recordings info and display it:
$itsAllGood = true;
try {$result = $bbb->getRecordingsWithXmlResponseArray($recordingsParams);}
    catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "\n";
        $itsAllGood = false;
    }

    if ($itsAllGood == true) {
        if ($result == null) {
            echo "Failed to get any response. Maybe we can't contact the BBB server.";
        }   
        else { 

         if ($result['returncode'] == 'SUCCESS') {
                echo "<p>Meeting info was found on the server.</p>";
            }


            else {
                echo "<p>Failed to get meeting info.</p>";
            }
            print_r($result);

        }
    }

When I am using Bigbluebutton, I need to retrieve the particular data from these XML format response.当我使用 Bigbluebutton 时,我需要从这些 XML 格式响应中检索特定数据。 I don't know how to retrieve the particular data from these XML format?我不知道如何从这些 XML 格式中检索特定数据?

Array
(
    [returncode] => SimpleXMLElement Object
        (
            [0] => SUCCESS
        )

    [0] => Array
        (
            [meetingId] => SimpleXMLElement Object
                (
                    [0] => newtech
                )                       
         )

    [1] => Array
        (
            [meetingId] => SimpleXMLElement Object
                (
                    [0] => menew
                )                          
        )  
)

I need to display the values of meetingId.我需要显示 meetingId 的值。

If you'd rather work with arrays you can cast the XML as well.如果您更喜欢使用数组,您也可以转换 XML。 This function returns an array with info on what is going on on your server if called (improvements still very welcome):如果调用此函数,则返回一个包含有关服务器上正在发生的事情的信息的数组(仍然非常欢迎改进):



    function getServerInfo() {
        $url="https://you-bbb-server-api-getMeetings-call-url";
        $a= (array)new SimpleXMLElement(file_get_contents($url));
        if($a["returncode"]=="SUCCESS") {
            if($a["meetings"]) {
               foreach($a["meetings"] as $meeting) {
                    $meeting=(array)$meeting;
                    $data["Meetings"][$meeting["meetingID"]]["Teilnehmer"]=$meeting["participantCount"];
                    $data["Meetings"][$meeting["meetingID"]]["Name"]=$meeting["meetingName"];
                    $data["Gesamt"]+=(int)$meeting["participantCount"];
                    $data["Anzahl"]++;
                    $data["Meetings"][$meeting["meetingID"]]["Video"]=$meeting["videoCount"];
                    $data["Meetings"][$meeting["meetingID"]]["Start"]=date('d.m.Y H:i:s',floor($meeting["startTime"]/1000));
                    if($meeting["attendees"]) foreach($meeting["attendees"] as $att) {
                        $att=(array)$att;
                        if($att["role"]=="MODERATOR") $data["Meetings"][$meeting["meetingID"]]["Liste"]["M"]=array($att["fullName"],($att["hasJoinedVoice"]=="true")? 1:0,($att["hasVideo"]=="true")? 1:0);
                        else $data["Meetings"][$meeting["meetingID"]]["Liste"]["T"][]=array($att["fullName"],($att["hasJoinedVoice"]=="true")? 1:0,($att["hasVideo"]=="true")? 1:0);
                    }
                }
                return($data);
            } else return(array("Anzahl"=>0,"Gesamt"=>0));
        } else return(-1);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM