当前位置: 首页>>代码示例>>PHP>>正文


PHP Convert::xml2array方法代码示例

本文整理汇总了PHP中Convert::xml2array方法的典型用法代码示例。如果您正苦于以下问题:PHP Convert::xml2array方法的具体用法?PHP Convert::xml2array怎么用?PHP Convert::xml2array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Convert的用法示例。


在下文中一共展示了Convert::xml2array方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAuthenticatedPUT

    public function testAuthenticatedPUT()
    {
        $comment1 = $this->objFromFixture('SoapModelAccessTest_Comment', 'comment1');
        $comment1ID = $comment1->ID;
        // test wrong details
        $c = $this->getTestSoapConnection();
        $updateXML = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
\t\t<SoapModelAccessTest_Comment>
\t\t\t<ID>{$comment1ID}</ID>
\t\t\t<Name>Jimmy</Name>
\t\t</SoapModelAccessTest_Comment>\t\t\t
XML;
        $soapResponse = $c->putXML("SoapModelAccessTest_Comment", $comment1->ID, null, $updateXML, 'editor@test.com', 'wrongpassword');
        $this->assertEquals('<error type="authentication" code="401">Unauthorized</error>', $soapResponse);
        // Check that the details weren't saved
        $c = $this->getTestSoapConnection();
        $soapResponse = $c->getXML("SoapModelAccessTest_Comment", $comment1->ID, null, 'editor@test.com', 'editor');
        $responseArr = Convert::xml2array($soapResponse);
        $this->assertEquals($comment1->ID, $responseArr['ID']);
        $this->assertEquals('Joe', $responseArr['Name']);
        // Now do an update with the right password
        $soapResponse = $c->putXML("SoapModelAccessTest_Comment", $comment1->ID, null, $updateXML, 'editor@test.com', 'editor');
        // Check that the details were saved
        $c = $this->getTestSoapConnection();
        $soapResponse = $c->getXML("SoapModelAccessTest_Comment", $comment1->ID, null, 'editor@test.com', 'editor');
        $responseArr = Convert::xml2array($soapResponse);
        $this->assertEquals($comment1->ID, $responseArr['ID']);
        $this->assertEquals('Jimmy', $responseArr['Name']);
    }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:30,代码来源:SoapModelAccessTest.php

示例2: Summary

	/**
	 * Create a summary of the content. This will either be the first paragraph, or the first $maxWords 
	 * words, whichever is shorter
	 */
	public function Summary( $maxWords = 50 ) {
		// split the string into tags and words
		$parts = Convert::xml2array( $this->value );
		
		// store any unmatched tags
		$tagStack = array();
		
		$pIndex = 0;
		
		// find the first paragraph tag
		for( $i = 0; $i < count( $parts ); $i++ )
			if( strpos( $parts[$i], '<p' ) === 0 ) {
				$pIndex = $i;
				break;
			}
				
		$summary = '';
		$words = 0;
		
		// create the summary, keeping track of opening and closing tags
		while( $words <= $maxWords && $pIndex < count( $parts ) ) {
			if( $parts[$pIndex] == '</p>' ) {
				$summary .= $parts[$pIndex];
				break;
			}
			elseif( preg_match( '/<\/(\w+)>/', $parts[$pIndex], $endTag ) && $endTag[1] == substr( $tagStack[count($tagStack) - 1], 1, strlen( $endTag[1] ) ) ) {
				array_pop( $tagStack );
				$words++;
				$summary .= $parts[$pIndex++];
			} elseif( preg_match( '/^<\w+/', $parts[$pIndex] ) ) {
				array_push( $tagStack, $parts[$pIndex] );
				$words++;
				$summary .= $parts[$pIndex++];
			} else
				$summary .= $parts[$pIndex++] . ' ';
		}
		
		// Tags that shouldn't be closed
		$noClose = array("br", "img");
		
		// make sure that the summary is well formed XHTML by closing tags
		while( $openTag = array_pop( $tagStack ) ) {
			preg_match( '/^<(\w+)\s+/', $openTag, $tagName );
			if(sizeof($tagName) > 0) {
			    if(!in_array($tagName[1], $noClose)) {
					$summary .= "</{$tagName[1]}>";
			    }
			}
		}
		
		return $summary;
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:56,代码来源:HTMLText.php

示例3: testXML2Array

    /**
     * Tests {@link Convert::xml2array()}
     */
    public function testXML2Array()
    {
        // Ensure an XML file at risk of entity expansion can be avoided safely
        $inputXML = <<<XML
<?xml version="1.0"?>
<!DOCTYPE results [<!ENTITY long "SOME_SUPER_LONG_STRING">]>
<results>
    <result>Now include &long; lots of times to expand the in-memory size of this XML structure</result>
    <result>&long;&long;&long;</result>
</results>
XML;
        try {
            Convert::xml2array($inputXML, true);
        } catch (Exception $ex) {
        }
        $this->assertTrue(isset($ex) && $ex instanceof InvalidArgumentException && $ex->getMessage() === 'XML Doctype parsing disabled');
        // Test without doctype validation
        $expected = array('result' => array("Now include SOME_SUPER_LONG_STRING lots of times to expand the in-memory size of this XML structure", array('long' => array(array('long' => 'SOME_SUPER_LONG_STRING'), array('long' => 'SOME_SUPER_LONG_STRING'), array('long' => 'SOME_SUPER_LONG_STRING')))));
        $result = Convert::xml2array($inputXML, false, true);
        $this->assertEquals($expected, $result);
        $result = Convert::xml2array($inputXML, false, false);
        $this->assertEquals($expected, $result);
    }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:26,代码来源:ConvertTest.php

示例4: convertStringToArray

 public function convertStringToArray($strData)
 {
     return Convert::xml2array($strData);
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:4,代码来源:XMLDataFormatter.php

示例5: testApiAccessWithPOST

 public function testApiAccessWithPOST()
 {
     $url = "/api/v1/RestfulServerTest_AuthorRating";
     $data = array('Rating' => '42', 'WriteProtectedField' => 'haxx0red');
     $response = Director::test($url, $data, null, 'POST');
     // Assumption: XML is default output
     $responseArr = Convert::xml2array($response->getBody());
     $this->assertEquals($responseArr['Rating'], 42);
     $this->assertNotEquals($responseArr['WriteProtectedField'], 'haxx0red');
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:10,代码来源:RestfulServerTest.php

示例6: complete

 /**
  * Manages the 'return' and 'cancel' replies
  */
 function complete()
 {
     $this->extend("EwayPayment_Handler_completion_start");
     if (isset($_REQUEST['code']) && ($code = $_REQUEST['code'])) {
         $params = explode('-', $code);
         if (count($params) == 2) {
             $payment = EwayPayment::get()->byID(intval($params[0]));
             if ($payment && $payment->AuthorisationCode == $params[1]) {
                 if (isset($_REQUEST['AccessPaymentCode'])) {
                     $url = $payment->EwayConfirmationURL($_REQUEST['AccessPaymentCode']);
                     $response = file_get_contents($url);
                     if ($response) {
                         $response = Convert::xml2array($response);
                         if (isset($response['ResponseCode']) && $response['ResponseCode'] == '00') {
                             $payment->Status = 'Success';
                         } else {
                             $payment->Status = 'Failure';
                         }
                     } else {
                         $payment->Status = 'Failure';
                     }
                     $payment->write();
                     $payment->redirectToOrder();
                 }
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-payment-eway,代码行数:31,代码来源:EwayPayment.php


注:本文中的Convert::xml2array方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。