本文整理汇总了PHP中SimpleXMLElement::count方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::count方法的具体用法?PHP SimpleXMLElement::count怎么用?PHP SimpleXMLElement::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertToArray
public function convertToArray()
{
try {
$allData = array();
$eachData = array();
$con = file_get_contents($this->file);
$con = trim($con);
$xml = new SimpleXMLElement($con);
if ($xml->count() > 0) {
foreach ($xml->children() as $element) {
if ($element->count() > 0) {
$this->parseTheNestedXML($element, $eachData);
$eachData = $eachData[$element->getName()];
} else {
$this->addValueToArray($key, $element, $eachData);
}
$eachData = $this->cleanArrayKeys($eachData);
$allData[] = $eachData;
$eachData = array();
}
} else {
$ret = $this->extractValue($xml, "//" . $xml->getName());
$eachData[$xml->getName()] = $ret;
$allData[] = $eachData;
}
return $allData;
} catch (Exception $e) {
print "Something went wrong..\n";
echo $e->getMessage();
exit;
}
}
示例2: _validateStructure
/**
* Validate if children have same number of children.
* @param SimpleXMLElement $complexDataXmlNode
* @return boolean
*/
protected function _validateStructure($complexDataXmlNode)
{
if ($complexDataXmlNode->count() == 0) {
return true;
}
$expectedChildren = null;
$expectedChildrenCount = 0;
foreach ($complexDataXmlNode->children() as $enumItem) {
if ($expectedChildren == null) {
/* @var $enumItemChild SimpleXMLElement */
foreach ($enumItem->children() as $nodeName => $enumItemChild) {
$expectedChildrenCount++;
$expectedChildren[$nodeName] = true;
}
continue;
}
if ($enumItem->count() != $expectedChildrenCount) {
return false;
}
$compareFrom = Mage::helper('xmlimport')->xmlChildrenToArray($enumItem);
if (count(array_diff_key($compareFrom, $expectedChildren)) != 0) {
return false;
}
}
return true;
}
示例3: buildArray
/**
* @param \SimpleXMLElement $node
* @param string $pseudoRegex
* @param array $previousRegex
* @return array
*/
protected function buildArray(\SimpleXMLElement $node, $pseudoRegex = '', array $previousRegex = [])
{
$routes = [];
if ($node->count() > 0) {
foreach ($node as $i => $routeXml) {
$route = [];
foreach ($routeXml->attributes() as $name => $attribute) {
if ($name === 'match') {
$regex = "{$pseudoRegex}/{$attribute}";
} else {
if (in_array($name, ['module', 'controller', 'action'], true)) {
$route['matches'][$name] = (string) $attribute;
} else {
if ($name === 'methods') {
$route['methods'] = array_map('strtoupper', explode(',', (string) $attribute));
} else {
$route['regex'][$name] = (string) $attribute;
}
}
}
}
$currentRegex = isset($route['regex']) ? $route['regex'] : [];
$route['regex'] = $currentRegex + $previousRegex;
$routes[$regex] = $route;
if ($routeXml->count() > 0) {
$routes = array_merge($routes, $this->buildArray($routeXml, $regex, $route['regex']));
}
}
}
return $routes;
}
示例4: parseNode
/**
* Returns array representation of XML data, starting from a node pointed by
* $node variable.
*
* Please see the documentation of this class for details about the internal
* representation of XML data.
*
* @param \SimpleXMLElement $node A node to start parsing from
* @return mixed An array representing parsed XML node or string value if leaf
*/
protected function parseNode(\SimpleXMLElement $node)
{
$parsedNode = [];
if ($node->count() === 0) {
return (string) $node;
}
foreach ($node->children() as $child) {
$nameOfChild = $child->getName();
$parsedChild = $this->parseNode($child);
if (count($child->attributes()) > 0) {
$parsedAttributes = '';
foreach ($child->attributes() as $attributeName => $attributeValue) {
if ($this->isDistinguishingAttribute($attributeName)) {
$parsedAttributes .= '[@' . $attributeName . '="' . $attributeValue . '"]';
}
}
$nameOfChild .= $parsedAttributes;
}
if (!isset($parsedNode[$nameOfChild])) {
// We accept only first child when they are non distinguishable (i.e. they differs only by non-distinguishing attributes)
$parsedNode[$nameOfChild] = $parsedChild;
}
}
return $parsedNode;
}
示例5: sendAllSMS
public function sendAllSMS()
{
$dataArray = $this->getAuthData();
if (!$this->queue->count()) {
return false;
}
$dataArray['action'] = 'xml_queue';
return $this->getAnswer((string) $this->httpClient->post($this->apiScript, ['query' => $dataArray, 'xml' => $this->queue->asXML()])->getBody());
}
示例6: parseResponse
/**
* Parses XML response from AWIS and displays selected data
* @param String $response xml response from AWIS
*/
public static function parseResponse($response)
{
$xml = new SimpleXMLElement($response, null, false, 'http://awis.amazonaws.com/doc/2005-07-11');
if ($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) {
$info = $xml->Response->UrlInfoResult->Alexa;
$nice_array = array('Phone Number' => $info->ContactInfo->PhoneNumbers->PhoneNumber, 'Owner Name' => $info->ContactInfo->OwnerName, 'Email' => $info->ContactInfo->Email, 'Street' => $info->ContactInfo->PhysicalAddress->Streets->Street, 'City' => $info->ContactInfo->PhysicalAddress->City, 'State' => $info->ContactInfo->PhysicalAddress->State, 'Postal Code' => $info->ContactInfo->PhysicalAddress->PostalCode, 'Country' => $info->ContactInfo->PhysicalAddress->Country, 'Links In Count' => $info->ContentData->LinksInCount, 'Rank' => $info->TrafficData->Rank);
}
foreach ($nice_array as $k => $v) {
echo $k . ': ' . $v . "\n";
}
}
示例7: SimpleXMLElement
function parse_countries_list()
{
$countries_xml = file_get_contents($this->user['folder'] . "/templates/countries.xml");
$xml = new SimpleXMLElement($countries_xml);
$count = $xml->count();
$return = "";
for ($i = 0; $i < $count; $i++) {
$return .= $xml->option[$i]->asXML();
}
return $return;
}
示例8: parseRouteParams
/**
* @param \SimpleXMLElement $route
* @param $name
* @return array
*/
private function parseRouteParams(\SimpleXMLElement $route, string $name)
{
$params = [];
if (!$route->count()) {
return $params;
}
foreach ($route->param as $position => $param) {
$params = array_merge($params, $this->parseRouteParam($name, $param, $position));
}
return $params;
}
示例9: getFlickrData
public function getFlickrData()
{
$url = "https://api.flickr.com/services/feeds/photos_public.gne?tags=chamonix%2cski%2csnow";
$xmlFileData = file_get_contents($url);
$xmlData = new SimpleXMLElement($xmlFileData);
if ($xmlData->count() > 0) {
$jsonData = json_encode($xmlData);
return $jsonData;
}
return false;
}
示例10: parseResponse
/**
* Parses XML response from AWIS and displays selected data
* @param String $response xml response from AWIS
*/
public static function parseResponse($response)
{
try {
$xml = new SimpleXMLElement($response, null, false, 'http://awis.amazonaws.com/doc/2005-07-11');
if ($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) {
$info = $xml->Response->UrlInfoResult->Alexa;
return $info;
}
} catch (Exception $e) {
echo 'Exception: ' . $response;
exit;
}
}
示例11: makeUserTable
public function makeUserTable()
{
$domains = isset($_POST['domain_list']) ? htmlspecialchars($_POST['domain_list']) : '';
$domainArray = array();
if ($domains !== '') {
$domainsArray = explode("\n", $domains);
}
$userModel = new UserModel();
$userModel->cleanTable();
foreach ($domainsArray as $siteName) {
$site = str_replace("\r", "", $siteName);
$accessKeyId = "AKIAJGMJHABBXMYJDXTQ";
$secretAccessKey = "u2KzeMmzyymW0OyXTWcqukssiguYBWxe1otpkyhE";
$ActionName = 'UrlInfo';
$ResponseGroupName = 'Rank,ContactInfo,LinksInCount';
$ServiceHost = 'awis.amazonaws.com';
$NumReturn = 10;
$StartNum = 1;
$SigVersion = '2';
$HashAlgorithm = 'HmacSHA256';
$params = array('Action' => $ActionName, 'ResponseGroup' => $ResponseGroupName, 'AWSAccessKeyId' => $accessKeyId, 'Timestamp' => gmdate("Y-m-d\\TH:i:s.\\0\\0\\0\\Z", time()), 'Count' => $NumReturn, 'Start' => $StartNum, 'SignatureVersion' => $SigVersion, 'SignatureMethod' => $HashAlgorithm, 'Url' => $site);
ksort($params);
$keyvalue = array();
foreach ($params as $k => $v) {
$keyvalue[] = $k . '=' . rawurlencode($v);
}
$queryParams = implode('&', $keyvalue);
$sign = "GET\n" . strtolower($ServiceHost) . "\n/\n" . $queryParams;
$sig1 = base64_encode(hash_hmac('sha256', $sign, $secretAccessKey, true));
$sig = rawurlencode($sig1);
$url = 'http://' . $ServiceHost . '/?' . $queryParams . '&Signature=' . $sig;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$xml = new \SimpleXMLElement($result, null, false, 'http://awis.amazonaws.com/doc/2005-07-11');
if ($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) {
$info = $xml->Response->UrlInfoResult->Alexa;
$nice_array = array('Rank' => $info->TrafficData->Rank);
}
$rank = $nice_array['Rank'];
//put into table
$userModel = new UserModel();
$userModel->rank = $rank;
$userModel->name = $site;
$userModel->save();
}
return redirect()->intended('domainTable');
}
示例12: iShouldSeeTheCorrectSitemapElements
/**
* @Then I should see the correct sitemap elements
* @And I should see the correct sitemap elements
*/
public function iShouldSeeTheCorrectSitemapElements()
{
// Grab sitemap.xml page contents and parse it as XML using SimpleXML library
$sitemap_contents = $this->getSession()->getDriver()->getContent();
try {
$xml = new SimpleXMLElement($sitemap_contents);
} catch (Exception $e) {
throw new Exception('Unable to read sitemap xml content - ' . $e->getMessage());
}
// check if <url> nodes exist
if (!($xml->count() > 0 && isset($xml->url))) {
throw new InvalidArgumentException('No urlset found');
}
}
示例13: getLocalizedTagContent
/**
* @param \SimpleXMLElement $element
* @param string $locale
*
* @return string
*
* @throws \Exception
*/
protected function getLocalizedTagContent(\SimpleXMLElement $element, $locale = null)
{
if (0 === $element->count()) {
return '';
}
if (null === $locale) {
return $this->multilineRemoveIndent((string) $element, 'true' === (string) $element->attributes()['removeIndent']);
}
foreach ($element as $node) {
if ($locale == (string) $node->attributes()['locale']) {
return $this->multilineRemoveIndent((string) $node, 'true' === (string) $node->attributes()['removeIndent']);
}
}
$message = sprintf('Locale "%s" not available in node "%s".', $locale, $element->getName());
throw new \Exception($message);
}
示例14: getSearchMetadata
/**
* @param \SimpleXMLElement $property
* @param string $className
*
* @return PropertyCollectionSearchMetadata
*/
protected function getSearchMetadata(\SimpleXMLElement $property, $className)
{
$fieldElementAttributes = $property->attributes();
$field = (string) $fieldElementAttributes->{'field'};
$multipleSearchMetadata = $this->propertySearchMetadataFactory->createCollection($className, $field);
if ($property->count() > 0) {
foreach ($property->children() as $metadata) {
$fieldElementAttributes = $metadata->attributes();
$propertyMetadata = $this->getPropertyMetadata($fieldElementAttributes, $className, $field);
$multipleSearchMetadata->propertySearchMetadata[] = $propertyMetadata;
}
} else {
$propertyMetadata = $this->getPropertyMetadata($fieldElementAttributes, $className, $field);
$multipleSearchMetadata->propertySearchMetadata[] = $propertyMetadata;
}
return $multipleSearchMetadata;
}
示例15: convertToArray
/**
* @param SimpleXMLElement $node
* @return array
*/
private function convertToArray(SimpleXMLElement $node)
{
$result = array();
$nodeData = array();
/** @var $attribute SimpleXMLElement */
foreach ($node->attributes() as $attribute) {
$nodeData[$attribute->getName()] = (string) $attribute;
}
if ($node->count()) {
$nodeData['node-value'] = array();
foreach ($node as $child) {
$nodeData['node-value'][] = $this->convertToArray($child);
}
} else {
$value = trim((string) $node);
$nodeData['node-value'] = $value;
}
$result[$node->getName()] = $nodeData;
return $result;
}