本文整理汇总了PHP中XMLParser::parseTextStruct方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLParser::parseTextStruct方法的具体用法?PHP XMLParser::parseTextStruct怎么用?PHP XMLParser::parseTextStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLParser
的用法示例。
在下文中一共展示了XMLParser::parseTextStruct方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseEmails
/**
* Parse into structures the XML contents of an email data file.
* @param $contents string
* @return array
*/
function parseEmails($contents)
{
$parser = new XMLParser();
$result = $parser->parseTextStruct($contents, array('email_text', 'subject', 'body'));
$parser->destroy();
return $result;
}
示例2: solrQuery
function solrQuery(&$xmlDoc)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->getSetting('solrUrl') . '/update');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type:text/xml; charset=utf-8"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POSTFIELDS, XMLCustomWriter::getXml($xmlDoc));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
fatalError('CURL Error: ' . curl_error($ch));
} else {
curl_close($ch);
$xmlParser = new XMLParser();
$result = null;
@($result =& $xmlParser->parseTextStruct($data, array("int")));
if ($result) {
foreach ($result as $nodeSet) {
foreach ($nodeSet as $node) {
if (isset($node['attributes']['name']) && $node['attributes']['name'] == 'status' && $node['value'] == 0) {
return true;
}
}
}
}
return false;
}
}
示例3: searchResults
/**
* Display search results.
*/
function searchResults()
{
ZendSearchHandler::setupTemplate();
$plugin =& PluginRegistry::getPlugin('generic', 'ZendSearchPlugin');
$isUsingSolr = $plugin->isUsingSolr();
if ($isUsingSolr) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $plugin->getSetting('solrUrl') . '/select');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, 0);
curl_setopt($ch, CURLOPT_POST, 1);
$query = '';
} else {
$index =& $plugin->getIndex();
$query = new Zend_Search_Lucene_Search_Query_Boolean();
}
$q = Request::getUserVar('q');
if (!empty($q)) {
if ($isUsingSolr) {
$query .= 'text:"' . ZendSearchHandler::luceneEscape($q) . '" ';
} else {
$query->addSubquery(Zend_Search_Lucene_Search_QueryParser::parse($q));
}
}
$searchFormElementDao =& DAORegistry::getDAO('SearchFormElementDAO');
$searchFormElements =& $searchFormElementDao->getSearchFormElements();
while ($searchFormElement =& $searchFormElements->next()) {
$searchFormElementId = $searchFormElement->getSearchFormElementId();
$symbolic = $searchFormElement->getSymbolic();
switch ($searchFormElement->getType()) {
case SEARCH_FORM_ELEMENT_TYPE_SELECT:
case SEARCH_FORM_ELEMENT_TYPE_STRING:
$term = Request::getUserVar($symbolic);
if (!empty($term)) {
if ($isUsingSolr) {
$query .= $symbolic . ':"' . ZendSearchHandler::luceneEscape($term) . '" ';
} else {
$query->addSubquery(new Zend_Search_Lucene_Search_Query_Term(new Zend_Search_Lucene_Index_Term($term, $symbolic)), true);
}
}
break;
case SEARCH_FORM_ELEMENT_TYPE_DATE:
$from = Request::getUserDateVar($symbolic . '-from');
$to = Request::getUserDateVar($symbolic . '-to');
if (!empty($from) && !empty($to)) {
if ($isUsingSolr) {
$query .= $symbolic . ':[' . strftime('%Y-%m-%dT%H:%M:%SZ', $from) . ' TO ' . strftime('%Y-%m-%dT%H:%M:%SZ', $to) . '] ';
} else {
$fromTerm = new Zend_Search_Lucene_Index_Term($from, $symbolic);
$toTerm = new Zend_Search_Lucene_Index_Term($to, $symbolic);
$query->addSubquery(new Zend_Search_Lucene_Search_Query_Range($fromTerm, $toTerm, true), true);
}
}
break;
default:
fatalError('Unknown element type!');
}
unset($searchFormElement);
}
$rangeInfo =& PKPHandler::getRangeInfo('results');
if ($isUsingSolr) {
$itemsPerPage = Config::getVar('interface', 'items_per_page');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'q=' . trim(urlencode($query)) . '&rows=' . urlencode($itemsPerPage) . ($rangeInfo ? '&start=' . $rangeInfo->getPage() * $itemsPerPage : ''));
$data = curl_exec($ch);
$xmlParser = new XMLParser();
$result = null;
$numFound = 0;
@($result =& $xmlParser->parseTextStruct($data, array('str', 'result')));
$recordIds = array();
if ($result) {
foreach ($result as $nodeSet) {
foreach ($nodeSet as $node) {
if (isset($node['attributes']['name']) && $node['attributes']['name'] == 'id') {
$recordIds[] = $node['value'];
} elseif (isset($node['attributes']['numFound'])) {
$numFound = $node['attributes']['numFound'];
}
}
}
}
$plugin->import('SolrResultIterator');
$resultsIterator =& SolrResultIterator::fromRangeInfo($recordIds, $numFound, $rangeInfo);
unset($recordIds);
} else {
$resultsArray = $index->find($query);
$plugin->import('ZendSearchResultIterator');
$resultsIterator =& ZendSearchResultIterator::fromRangeInfo($resultsArray, $rangeInfo);
unset($resultsArray);
}
$templateMgr =& TemplateManager::getManager();
$templateMgr->assign_by_ref('recordDao', DAORegistry::getDAO('RecordDAO'));
$templateMgr->assign_by_ref('results', $resultsIterator);
$templateMgr->assign_by_ref('q', $q);
//.........这里部分代码省略.........