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


PHP str_get_dom函数代码示例

本文整理汇总了PHP中str_get_dom函数的典型用法代码示例。如果您正苦于以下问题:PHP str_get_dom函数的具体用法?PHP str_get_dom怎么用?PHP str_get_dom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: testTag

 public function testTag()
 {
     $this->client->get('/tag/lorem');
     $this->assertEquals(200, $this->client->response->status());
     $html = str_get_dom($this->client->response->body());
     $this->assertEquals(1, count($html('div.blog-post')));
 }
开发者ID:lamenath,项目名称:fbp,代码行数:7,代码来源:IntegrationTest.php

示例2: file_get_dom

/**
 * Returns HTML DOM from file/website
 * @param string $str
 * @param bool $return_root Return root node or return parser object
 * @param bool $use_include_path Use include path search in file_get_contents
 * @param resource $context Context resource used in file_get_contents (PHP >= 5.0.0)
 * @return Html5Parser|DomNode
 */
function file_get_dom($file, $return_root = true, $use_include_path = false, $context = null)
{
    if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
        $f = file_get_contents($file, $use_include_path, $context);
    } else {
        if ($context !== null) {
            trigger_error('Context parameter not supported in this PHP version');
        }
        $f = file_get_contents($file, $use_include_path);
    }
    return $f === false ? false : str_get_dom($f, $return_root);
}
开发者ID:tburry,项目名称:pquery,代码行数:20,代码来源:ganon.php

示例3: file_get_dom

function file_get_dom($file, $return_root = true, $use_include_path = false, $context = null)
{
    $ch = curl_init($file);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt_array($ch, $context);
    $f = curl_exec($ch);
    if ($f == false) {
        echo 'Curl error: ' . curl_errno($ch) . ":" . curl_error($ch) . "\n";
    }
    curl_close($ch);
    return $f === false ? false : str_get_dom($f, $return_root);
}
开发者ID:coolgod,项目名称:cmb-xr-crawler,代码行数:13,代码来源:ganon.php

示例4: getPage

function getPage($memcache, $pdo, $db, $__language, $__country, $path, $directives = null, $session = null, $facebook = null, $config = null)
{
    error_log('getPage: ' . $path);
    $editMode = false;
    if (!empty($session->admin) || !empty($session->contentcreator) || !empty($session->developer)) {
        $editMode = true;
    }
    $smarty = new templateVariablesParser();
    if (!empty($directives)) {
        foreach ($directives as $key => $value) {
            $smarty->set($key, $value);
        }
    }
    if (empty($__language) || empty($__country) || empty($path)) {
        error_log('getPage called with illegal parameters');
        return false;
    }
    $oReturn = getRequestDetails($path, true);
    if (!empty($oReturn->template)) {
        $template = $oReturn->template;
        if (!empty($oReturn->fullPath)) {
            // execute the template's  php file
            if (!empty($oReturn->extension)) {
                $phpFile = str_ireplace('.' . $oReturn->extension, '.php', $oReturn->fullPath);
                if (is_file($phpFile)) {
                    include $phpFile;
                }
            }
        }
        $_path = $path;
        if (!empty($template)) {
            // iterate the dom elements that have an id, and replace elements that are found in the database
            $dom = str_get_dom(implode('', $template));
            foreach ($dom("*[id!='']") as $element) {
                if (!empty($element->id)) {
                    // if the directive '_parent' is set, then translate tags marked for the parent page i.e. set the page to whatever the parent page is
                    // if it is not set, then use the include src as page
                    if (!empty($directives)) {
                        if (!empty($directives['target'])) {
                            switch ($directives['target']) {
                                case 'parent':
                                case '_parent':
                                    $_path = $directives['parent'];
                                    break;
                                default:
                                    $_path = $directives['target'];
                                    break;
                            }
                        }
                    }
                    $content = getTagContent($memcache, $pdo, $session, $element->id, $__language, $__country, $session->continent, $_path, 5);
                    if ($content !== false) {
                        $element->setOuterText($content);
                    }
                }
            }
            // evaluate condition
            // to enable conditions we have the following attributes available
            // tag must contain a condition attr like: condition="$session->language == 'en'"
            // we enable or disable the use of conditions in the config file
            if (defined('__CONDITIONS__')) {
                if (__CONDITIONS__) {
                    foreach ($dom('[condition]') as $element) {
                        $condition = html_entity_decode($element->condition, ENT_QUOTES, 'UTF-8');
                        error_log($condition);
                        $evaluated = false;
                        if (eval($condition) === true) {
                            $evaluated = true;
                            error_log('condition = true');
                        } else {
                            error_log('condition = false');
                        }
                        if (!$evaluated) {
                            $element->detach();
                        }
                        $element->deleteAttribute('condition');
                    }
                }
            }
            // get the smarty vars from the new template and replace the vars with content from the underlying php
            //    (index.html executes an index.php in that same directory
            $template = $smarty->parse($pdo, $memcache, $session, $__language, $__country, $session->region, $_path, (string) $dom);
            unset($smarty);
            // include css. (inline them if the inline tag is set), compile the scss into css, cache the css (or get from cache)
            $dom = str_get_dom($template);
            foreach ($dom('link') as $element) {
                if (!empty($element->href) && !empty($element->inline)) {
                    // check if src translates to a local css or scss file tha we can serve
                    if (strpos($element->href, '//') === false) {
                        $parts = explode('.', $element->href);
                        if (strtolower($parts[sizeof($parts) - 1]) == 'css' || strtolower($parts[sizeof($parts) - 1]) == 'scss') {
                            $scss = false;
                            if (strtolower($parts[sizeof($parts) - 1]) == 'scss') {
                                $scss = new scssc();
                            }
                            $fn = implode('.', $parts);
                            if ($fn[0] !== '/') {
                                $fullPathContent = DOCUMENT_ROOT . '/' . $fn;
                            } else {
                                $fullPathContent = DOCUMENT_ROOT . $fn;
//.........这里部分代码省略.........
开发者ID:khessels,项目名称:engine,代码行数:101,代码来源:contentManager.php

示例5: compare

 protected function compare()
 {
     $bench = new Ubench();
     $url = 'tests/templated-retrospect/index.html';
     $file = 'test.html';
     if (!file_exists($file)) {
         $htmlstr = file_get_contents($url);
         file_put_contents($file, $htmlstr);
     }
     $htmlstr = file_get_contents($file);
     $this->log('', true);
     $this->log('Measuring Simple HTML DOM Parser...');
     $resultsSimpleHtmlDomParser = $bench->run(function ($htmlstr) {
         $results = [];
         $html = HtmlDomParser::str_get_html($htmlstr);
         $html->find('title', 0)->innertext('New Title');
         $results[1] = $html->__toString();
         $tpl = HtmlDomParser::str_get_html(file_get_contents('tests/templated-retrospect/index.html'));
         foreach ($tpl->find('link') as $elem) {
             $elem->href = '//localhost/xparser/tests/templated-retrospect/' . $elem->href;
         }
         foreach ($tpl->find('img, script') as $elem) {
             $elem->src = '//localhost/xparser/tests/templated-retrospect/' . $elem->src;
         }
         $results[2] = $tpl->__toString();
         return $results;
     }, $htmlstr);
     //$this->log('distance: ' . similar_text($htmlstr, $result));
     $this->logBench($bench);
     $this->log('', true);
     $this->log('Measuring XParser...');
     $resultsXParser = $bench->run(function ($htmlstr) {
         $results = [];
         $html = new XNode($htmlstr);
         $html->find('title')->inner('New Title');
         $results[1] = $html->__toString();
         $tpl = new XNode(file_get_contents('tests/templated-retrospect/index.html'));
         foreach ($tpl('link') as $elem) {
             $elem->href = '//localhost/xparser/tests/templated-retrospect/' . $elem->href;
         }
         foreach ($tpl('img, script') as $elem) {
             $elem->src = '//localhost/xparser/tests/templated-retrospect/' . $elem->src;
         }
         $results[2] = $tpl->__toString();
         return $results;
     }, $htmlstr);
     //$this->log('distance: ' . similar_text($htmlstr, $result));
     $this->logBench($bench);
     $this->log('', true);
     $this->log('Measuring Ganon...');
     $resultsGanon = $bench->run(function ($htmlstr) {
         $html = str_get_dom($htmlstr);
         foreach ($html('title') as $title) {
             $title->setInnerText('New Title');
         }
         $results[1] = $html->__toString();
         $tpl = new XNode(file_get_contents('tests/templated-retrospect/index.html'));
         foreach ($tpl('link') as $elem) {
             $elem->href = '//localhost/xparser/tests/templated-retrospect/' . $elem->href;
         }
         foreach ($tpl('img, script') as $elem) {
             $elem->src = '//localhost/xparser/tests/templated-retrospect/' . $elem->src;
         }
         $results[2] = $tpl->__toString();
         return $results;
     }, $htmlstr);
     //$this->log('distance: ' . similar_text($htmlstr, $result));
     $this->logBench($bench);
     $this->log('', true);
     $this->log('Symfony CSS Selector combined with DOMDocument and DOMXPath...');
     $resultsXParser = $bench->run(function ($htmlstr) {
         $results = [];
         $html = new DOMDocument();
         libxml_use_internal_errors(true);
         $html->loadHTML($htmlstr);
         $converter = new CssSelectorConverter();
         $xpath = new DOMXPath($html);
         $elements = $xpath->query($converter->toXPath('title'));
         foreach ($elements as $element) {
             $element->innserHTML = 'New Title';
         }
         $results[1] = $html->saveHTML();
         $tpl = new DOMDocument();
         $tpl->load('tests/templated-retrospect/index.html');
         foreach ($xpath->query($converter->toXPath('link')) as $elem) {
             $elem->setAttribute('href', '//localhost/xparser/tests/templated-retrospect/' . $elem->getAttribute('href'));
         }
         foreach ($xpath->query($converter->toXPath('img, script')) as $elem) {
             $elem->setAttribute('src', '//localhost/xparser/tests/templated-retrospect/' . $elem->getAttribute('src'));
         }
         $results[2] = $tpl->saveHTML();
         return $results;
     }, $htmlstr);
     //$this->log('distance: ' . similar_text($htmlstr, $result));
     $this->logBench($bench);
     $this->log('', true);
     $this->log('Simple HTML DOM Parser vs Ganon distance: ' . similar_text($resultsSimpleHtmlDomParser[2], $resultsGanon[2]));
     $this->log('Simple HTML DOM Parser vs XParser distance: ' . similar_text($resultsSimpleHtmlDomParser[2], $resultsXParser[2]));
     $this->log('Ganon vs XParser distance: ' . similar_text($resultsGanon[2], $resultsXParser[2]));
     $this->log('', true);
//.........这里部分代码省略.........
开发者ID:gymadarasz,项目名称:xparser-benchmarks,代码行数:101,代码来源:XParserBenchmarks.php

示例6: parse

 /**
  *
  */
 public static function parse($ps_template, $pa_options = null)
 {
     $vs_cache_key = md5($ps_template);
     if (isset(DisplayTemplateParser::$template_cache[$vs_cache_key])) {
         return DisplayTemplateParser::$template_cache[$vs_cache_key];
     }
     $ps_template_original = $ps_template;
     // Parse template
     $o_doc = str_get_dom($ps_template);
     $ps_template = str_replace("<~root~>", "", str_replace("</~root~>", "", $o_doc->html()));
     // replace template with parsed version; this allows us to do text find/replace later
     $va_tags = DisplayTemplateParser::_getTags($o_doc->children, array_merge($pa_options, ['maxLevels' => 1]));
     if (!is_array(DisplayTemplateParser::$template_cache)) {
         DisplayTemplateParser::$template_cache = [];
     }
     return DisplayTemplateParser::$template_cache[$vs_cache_key] = ['original_template' => $ps_template_original, 'template' => $ps_template, 'tags' => $va_tags, 'tree' => $o_doc];
 }
开发者ID:samrahman,项目名称:providence,代码行数:20,代码来源:DisplayTemplateParser.php

示例7: parseProfile

 public static function parseProfile($page)
 {
     $html = str_get_dom($page);
     $name = $html('table');
     $data = array('student' => array('name' => $name[0]('tr td')[0]->getPlainText(), 'studentnumber' => $name[0]('tr td')[2]->getPlainText(), 'class' => $name[0]('tr td')[4]->getPlainText(), 'birthdate' => $name[1]('tr td')[1]->getPlainText(), 'phonenumbers' => array('home' => $name[1]('tr td')[3]->getPlainText(), 'mobile' => $name[1]('tr td')[5]->getPlainText())), 'address' => array('street' => $name[2]('tr td')[2]->getPlainText(), 'zipcode' => $name[2]('tr td')[4]->getPlainText(), 'residence' => $name[2]('tr td')[6]->getPlainText()), 'mentor' => array('name' => $name[3]('tr td')[2]->getPlainText(), 'abbreviation' => $name[3]('tr td')[4]->getPlainText(), 'email' => $name[3]('tr td')[6]->getPlainText()), 'profile' => array('profile' => $name[4]('tr td')[2]->getPlainText(), 'code' => $name[4]('tr td')[4]->getPlainText(), 'abbreviation' => $name[4]('tr td')[6]->getPlainText(), 'year' => $name[4]('tr td')[8]->getPlainText()));
     return $data;
 }
开发者ID:CWMCDev,项目名称:Barend,代码行数:7,代码来源:portal_student.php

示例8: array

$opciones = array('http' => array('method' => "GET", 'header' => "Accept-language: es\r\n" . 'User-agent: Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3'));
$contexto = stream_context_create($opciones);
$content = file_get_contents($loginUrl, false, $contexto);
$html = str_get_dom($content);
$inputs = $html('#form_search input');
$url = $loginUrl . '?';
$notparse = array('checkin_monthday' => '31', 'checkin_year_month' => '2013-10', 'checkout_year_month' => '2013-11', 'checkout_monthday' => '1', 'ci_date' => '2013-10-31', 'co_date' => '2013-11-1', 'search_form_id' => '192a1bab236301f7');
foreach ($inputs as $input) {
    if (!array_key_exists($input->name, $notparse)) {
        $url .= $input->name . '=' . urlencode($input->value) . '&';
    } else {
        $url .= $input->name . '=' . urlencode($notparse[$input->name]) . '&';
    }
}
$content = file_get_contents($url, false, $contexto);
$html = str_get_dom($content);
$apartamentos = $html('#bookForm ul li');
foreach ($apartamentos as $a) {
    echo '<h1>titulo</h1>';
    $titulo = $a('h2');
    echo $titulo[0]->getPlainTextUTF8();
    $imagenes = $a('.roomImage');
    echo '<h1>Imagen</h1>';
    foreach ($imagenes as $image) {
        echo $image->getAttribute('data-big-image') . '<br />';
    }
    echo '<h1>Precio</h1>';
    $precio = $a('.price');
    echo $precio[0]->getPlainTextUTF8();
    echo '<h1>Condiciones</h1>';
    $condiciones = $a('h3 span');
开发者ID:randyibarrola,项目名称:active,代码行数:31,代码来源:index.php

示例9: NearTAL_Compiler

 function NearTAL_Compiler(&$returnValue, $template, $page, $variables = null, $directories = null)
 {
     $compilerData = array('metal' => array(), 'keywords' => array('define', 'condition', 'repeat', 'replace', 'content', 'omit-tag', 'attributes'));
     if (file_exists($directories['templates']) && is_dir($directories['templates']) && file_exists($directories['templates'] . '/' . $template) && is_dir($directories['templates'] . '/' . $template) && (file_exists($directories['temp']) || mkdir($directories['temp'], 0700)) && is_dir($directories['temp'])) {
         if (file_exists($directories['templates'] . '/' . $template . '.metal.html') && false !== ($content = file_get_contents($directories['templates'] . '/' . $template . '.metal.html'))) {
             $parser = str_get_dom($content);
             NearTAL_Compiler_ParseMETAL($returnValue, $compilerData, $parser, false);
             unset($parser);
         }
         if (file_exists($directories['templates'] . '/' . $template . '/' . $page . '.html') && false !== ($content = file_get_contents($directories['templates'] . '/' . $template . '/' . $page . '.html'))) {
             $parser = str_get_dom($content);
             NearTAL_Compiler_ParseMETAL($returnValue, $compilerData, $parser, true);
             $nodes = $parser->select('[data-metal-use-macro]');
             foreach ($nodes as $node) {
                 $macroName = $node->getAttribute('data-metal-use-macro');
                 if (array_key_exists($macroName, $compilerData['metal'])) {
                     $availableSlots = array();
                     $slots = $node('[data-metal-fill-slot]');
                     foreach ($slots as $slot) {
                         $slotName = $slots->getAttribute('data-metal-fill-slot');
                         if (array_key_exists($slotName, $slots)) {
                             NearTAL_AddError($returnValue, constant('NearTAL_Error_DuplicatedSlot'), $slotName);
                         }
                         $slot->deleteAttribute('data-metal-fill-slot');
                         $availableSlots[$slotName] = $slot->getOuterText();
                     }
                     $node->setOuterText($compilerData['metal'][$macroName]);
                     $slots = $node('[data-metal-define-slot]');
                     foreach ($slots as $slot) {
                         $slotName = $slots->getAttribute('data-metal-define-slot');
                         if (array_key_exists($slotName, $availableSlots)) {
                             $slot->setOuterText($availableSlots[$slotName]);
                         } else {
                             $slot->deleteAttribute('data-metal-define-slot');
                             NearTAL_AddError($returnValue, constant('NearTAL_Error_UnknownSlot'), $slotName);
                         }
                     }
                     unset($availableSlots);
                 } else {
                     NearTAL_AddError($returnValue, constant('NearTAL_Error_UnknownMacro'), $macroName);
                 }
             }
             $output = '<?php if(defined(\'NearTAL\')){$localVariables=array(\'defined\'=>array(),\'repeat\'=>array(),\'stack\'=>array(\'defined\'=>array(),\'repeat\'=>array()),\'template\'=>array()); ?>';
             $localVariablesIndex = 0;
             $count = 0;
             $selectFilter = array();
             foreach ($compilerData['keywords'] as $keyword) {
                 $selectFilter[] = '[data-tal-' . $keyword . ']';
             }
             $nodes = $parser->select(implode(',', $selectFilter));
             $localVariablesIndex = 0;
             foreach ($nodes as $node) {
                 $changes = array('attributes' => array(), 'outside' => array('pre' => null, 'post' => null), 'inside' => array('pre' => null, 'post' => null));
                 foreach ($compilerData['keywords'] as $keyword) {
                     $attribute = trim($node->getAttribute('data-tal-' . $keyword));
                     if (!is_null($attribute)) {
                         if (!is_array($attribute) && !empty($attribute)) {
                             switch ($keyword) {
                                 case 'define':
                                     $tmpVariable = array();
                                     $tmpVariable['count'] = preg_match_all('/[\\s]*(?:(?:(local|world)[\\s]+)?(.+?)[\\s]+(.+?)[\\s]*(?:(?<!;);(?!;)|$))+?/', $attribute, $tmpVariable['elements'], PREG_SET_ORDER);
                                     for ($j = 0; $j < $tmpVariable['count']; $j++) {
                                         $tmpVariable['name'] = str_replace('\'', '&#039', $tmpVariable['elements'][$j][2]);
                                         $fastAnswers = NearTAL_Compiler_ParseTALES($tmpVariable['compiledExpression'], $tmpVariable['elements'][$j][3], $node->attributes, '$tmpVariable');
                                         $changes['outside']['pre'] .= '$localVariables[\'template\'][' . $localVariablesIndex . ']=(' . $tmpVariable['compiledExpression'] . '&&!$tmpVariable[1]);if($localVariables[\'template\'][' . $localVariablesIndex++ . ']){NearTAL_LocalVariablesPush($localVariables,\'defined\',\'' . $tmpVariable['name'] . '\',$tmpVariable[0]);}';
                                         if ('world' != $tmpVariable['elements'][$j][1]) {
                                             $changes['outside']['post'] = 'if($localVariables[\'template\'][' . ($localVariablesIndex - 1) . ']){NearTAL_LocalVariablesPop($localVariables,\'defined\',\'' . $tmpVariable['name'] . '\');unset($localVariables[\'template\'][' . ($localVariablesIndex - 1) . ']);}' . $changes['outside']['post'];
                                         }
                                     }
                                     break;
                                 case 'condition':
                                     $fastAnswers = NearTAL_Compiler_ParseTALES($tmpVariable['compiledExpression'], $attribute, $node->attributes, '$localVariables[\'template\'][' . $localVariablesIndex . ']', true, false);
                                     if ($fastAnswers[1]) {
                                         $node->delete();
                                     } else {
                                         $changes['outside']['pre'] .= 'if(' . $tmpVariable['compiledExpression'] . '){';
                                         $changes['outside']['post'] = '}unset($localVariables[\'template\'][' . $localVariablesIndex++ . ']);' . $changes['outside']['post'];
                                     }
                                     break;
                                 case 'repeat':
                                     $tmpVariable['elements'] = explode(" ", $attribute, 2);
                                     $tmpVariable['name'] = str_replace('\'', '&#039', $tmpVariable['elements'][0]);
                                     $fastAnswers = NearTAL_Compiler_ParseTALES($tmpVariable['compiledExpression'], $tmpVariable['elements'][1], $node->attributes, '$localVariables[\'template\'][' . $localVariablesIndex . ']');
                                     $changes['outside']['pre'] .= sprintf('if((%1$s)&&($localVariables[\'template\'][%2$d][1]||is_array($localVariables[\'template\'][%2$d][0]))){$localVariables[\'template\'][%3$d]=array(false,false);if(!$localVariables[\'template\'][%2$d][1]){($localVariables[\'template\'][%3$d][0]=true)&&NearTAL_LocalVariablesPush($localVariables,\'repeat\',\'%4$s\',null);($localVariables[\'template\'][%3$d][1]=true)&&NearTAL_LocalVariablesPush($localVariables,\'defined\',\'%4$s\',null);$localVariables[\'repeat\'][\'%4$s\'][\'index\']=-1;$localVariables[\'repeat\'][\'%4$s\'][\'length\']=count($localVariables[\'template\'][%2$d][0]);}do{if(!$localVariables[\'template\'][%2$d][1]){$localVariables[\'defined\'][\'%4$s\']=array_shift($localVariables[\'template\'][%2$d][0]);$localVariables[\'repeat\'][\'%4$s\'][\'index\']++;$localVariables[\'repeat\'][\'%4$s\'][\'number\']=$localVariables[\'repeat\'][\'%4$s\'][\'index\']+1;$localVariables[\'repeat\'][\'%4$s\'][\'even\']=($localVariables[\'repeat\'][\'%4$s\'][\'number\']%%2?true:false);$localVariables[\'repeat\'][\'%4$s\'][\'odd\']=!$localVariables[\'repeat\'][\'%4$s\'][\'even\'];$localVariables[\'repeat\'][\'%4$s\'][\'start\']=($localVariables[\'repeat\'][\'%4$s\'][\'index\']?false:true);$localVariables[\'repeat\'][\'%4$s\'][\'end\']=(($localVariables[\'repeat\'][\'%4$s\'][\'number\']==$localVariables[\'repeat\'][\'%4$s\'][\'length\'])?true:false);$localVariables[\'repeat\'][\'%4$s\'][\'letter\']=NearTAL_NumberToLetter($localVariables[\'repeat\'][\'%4$s\'][\'index\']);$localVariables[\'repeat\'][\'%4$s\'][\'Letter\']=strtoupper($localVariables[\'repeat\'][\'%4$s\'][\'letter\']);}', $tmpVariable['compiledExpression'], $localVariablesIndex++, $localVariablesIndex, $tmpVariable['name']);
                                     $changes['outside']['post'] = sprintf('}while(!$localVariables[\'template\'][%1$d][1]&&!empty($localVariables[\'template\'][%1$d][0]));$localVariables[\'template\'][%2$d][0]&&NearTAL_LocalVariablesPop($localVariables,\'repeat\',\'%3$s\');$localVariables[\'template\'][%2$d][1]&&NearTAL_LocalVariablesPop($localVariables,\'defined\',\'%3$s\');unset($localVariables[\'template\'][%1$d],$localVariables[\'template\'][%2$d]);}', $localVariablesIndex - 1, $localVariablesIndex++, $tmpVariable['name']) . $changes['outside']['post'];
                                     break;
                                 case 'replace':
                                 case 'content':
                                     if ('content' == $keyword || 'replace' == $keyword && !array_key_exists('data-tal-content', $node->attributes)) {
                                         $tmpVariable = array();
                                         if ('structure ' == substr($attribute, 0, 10) || 'text ' == substr($attribute, 0, 5)) {
                                             $tmpVariable['parameters'] = explode(" ", $attribute, 2);
                                         } else {
                                             $tmpVariable['parameters'] = array("text", $attribute);
                                         }
                                         $fastAnswers = NearTAL_Compiler_ParseTALES($tmpVariable['compiledExpression'], $tmpVariable['parameters'][1], $node->attributes, '$localVariables[\'template\'][' . $localVariablesIndex . ']');
                                         if (!$fastAnswers[0]) {
                                             if (!$fastAnswers[1]) {
                                                 $tmpVariable['pre'] = 'if(' . $tmpVariable['compiledExpression'] . '&&!$localVariables[\'template\'][' . $localVariablesIndex . '][1]&&!is_null($localVariables[\'template\'][' . $localVariablesIndex . '][0])){echo(' . ('text' == $tmpVariable['parameters'][0] ? 'str_replace(array(\'&\',\'<\',\'>\'),array(\'&amp\',\'&lt\',\'&gt\'),' : null) . '(is_bool($localVariables[\'template\'][' . $localVariablesIndex . '][0])?($localVariables[\'template\'][' . $localVariablesIndex . '][0]?1:0):$localVariables[\'template\'][' . $localVariablesIndex . '][0])' . ('text' == $tmpVariable['parameters'][0] ? ')' : null) . ');}elseif($localVariables[\'template\'][' . $localVariablesIndex . '][1]){';
                                                 $tmpVariable['post'] = '}unset($localVariables[\'template\'][' . $localVariablesIndex++ . ']);';
//.........这里部分代码省略.........
开发者ID:stefanobalocco,项目名称:neartal,代码行数:101,代码来源:NearTAL.Compiler.php

示例10: json_decode

         $innerHTML = false;
         $attributes = false;
         $bSetTag = true;
         if (!empty($_POST['attributes'])) {
             $attributes = json_decode(base64_decode($_POST['attributes']));
         }
         $path = $session->request->request;
         if (!empty($element->attributes)) {
             foreach ($element->attributes as $obj) {
                 if ($obj->name == 'data-src') {
                     $path = $obj->value;
                 }
             }
         }
         $element->outerHTML = str_replace('"', "'", $element->outerHTML);
         $dom = str_get_dom($element->outerHTML);
         $dom('img')[0]->src = $_POST['src'];
         $content = (string) $dom;
         $ret = setTag($session, $pdo, $memcache, $element->id, $session->language, $session->country, $session->continent, $path, $content);
         $json->id = $_POST['id'];
         $json->element = $element;
         if ($ret === false) {
             $json->status = 'ERROR';
             $json->message = 'Error setTag()';
         }
     } else {
         $json->status = 'ERROR';
         $json->message = 'Invalid element';
     }
 } else {
     $json->status = 'ERROR';
开发者ID:khessels,项目名称:engine,代码行数:31,代码来源:set-image-tag.php

示例11: str_get_dom

 $stmt->bindParam(':language', $obj->_language);
 $stmt->bindParam(':country', $obj->_country);
 $stmt->bindParam(':id', $obj->_id);
 $stmt->bindParam(':page', $obj->_page);
 $stmt->execute();
 $row = $stmt->fetch(PDO::FETCH_OBJ);
 if (empty($row)) {
     $sql = "SELECT\r\n                                            *\r\n                                        FROM `image-url-translations`\r\n                                        WHERE\r\n                                            url=:url AND\r\n                                            language=:language AND\r\n                                            country=:country";
     $stmt = $pdo->prepare($sql);
     $stmt->bindParam(':language', $obj->_language);
     $stmt->bindParam(':country', $obj->_country);
     $stmt->bindValue(':url', '/' . $obj->_seo_src . '.' . $obj->_image->extension);
     $stmt->execute();
     $row = $stmt->fetch(PDO::FETCH_OBJ);
     if (empty($row)) {
         $html = str_get_dom($obj->_content);
         $tags = $html();
         foreach ($tags as $i => $el) {
             $el->attributes['src'] = '/' . $obj->_seo_src . '.' . $obj->_image->extension;
             $el->attributes['alt'] = $obj->_alt;
             $el->attributes['title'] = $obj->_title;
             break;
         }
         $obj->_content = (string) $html;
         $sql = "INSERT INTO\r\n                                                    tags\r\n                                                  SET\r\n                                                    language=:language,\r\n                                                    country=:country,\r\n                                                    element_id=:id,\r\n                                                    page=:page,\r\n                                                    content=:content";
         $stmt = $pdo->prepare($sql);
         $stmt->bindParam(':language', $obj->_language);
         $stmt->bindParam(':country', $obj->_country);
         $stmt->bindParam(':id', $obj->_id);
         $stmt->bindValue(':page', $obj->_page);
         $stmt->bindValue(':content', $obj->_content);
开发者ID:khessels,项目名称:engine,代码行数:31,代码来源:set-image-seo-tag.php

示例12: number_format

echo '<br><br>[load file]<br>init memory: ' . number_format(memory_get_usage(), 0, '.', ',') . '<br>';
echo '------------------------------------------<br>';
flush();
for ($i = 0; $i < 3; ++$i) {
    $str = file_get_contents($filename);
    unset($str);
    dump_memory();
}
echo 'final: ' . number_format(memory_get_usage(), 0, '.', ',') . '<br>';
flush();
$str = file_get_contents($filename);
echo '<br><br>[multi objects str_get_dom clear memory]<br>init memory: ' . number_format(memory_get_usage(), 0, '.', ',') . '<br>';
echo '------------------------------------------<br>';
flush();
for ($i = 0; $i < 3; ++$i) {
    $dom = str_get_dom($str);
    //stat_dom($dom);
    $dom->clear();
    unset($dom);
    dump_memory();
    flush();
}
echo 'final: ' . number_format(memory_get_usage(), 0, '.', ',') . '<br>';
flush();
echo '<br><br>[multi objects file_get_dom clear memory]<br>init memory: ' . number_format(memory_get_usage(), 0, '.', ',') . '<br>';
echo '------------------------------------------<br>';
flush();
for ($i = 0; $i < 3; ++$i) {
    $dom = file_get_dom($filename);
    //stat_dom($dom);
    $dom->clear();
开发者ID:a-barzanti,项目名称:sainsburys,代码行数:31,代码来源:memory_test.php

示例13: caCreateLinksFromText

/**
 * Creates links to the appropriate editor (in Providence) or detail page (in Pawtucket) from supplied text and ids.
 * Used in SearchResult::get() and BundlableLabelableBaseModelWithAttributes::get() to automatically generate links when fetching
 * information from related tables.
 *
 * @param array $pa_text An array of strings to create links for
 * @param string $ps_table_name The name of the table/record to which the links refer
 * @param array $pa_row_ids Array of row_ids to link to. Values must correspond by index with those in $pa_text
 * @param string $ps_class Optional CSS class to apply to links
 * @param string $ps_target
 * @param array $pa_options Supported options are:
 *		requireLinkTags = if set then links are only added when explicitly defined with <l> tags. Default is to make the entire text a link in the absence of <l> tags.
 * 		addRelParameter =
 *
 * @return array A list of HTML links
 */
function caCreateLinksFromText($pa_text, $ps_table_name, $pa_row_ids, $ps_class = null, $ps_target = null, $pa_options = null)
{
    if (!in_array(__CA_APP_TYPE__, array('PROVIDENCE', 'PAWTUCKET'))) {
        return $pa_text;
    }
    if (__CA_APP_TYPE__ == 'PAWTUCKET') {
        $o_config = Configuration::load();
    }
    $pb_add_rel = caGetOption('addRelParameter', $pa_options, false);
    $vb_can_handle_target = false;
    if ($ps_target) {
        $o_app_plugin_manager = new ApplicationPluginManager();
        $vb_can_handle_target = $o_app_plugin_manager->hookCanHandleGetAsLinkTarget(array('target' => $ps_target));
    }
    // Parse template
    $o_doc = str_get_dom($ps_template);
    $va_links = array();
    global $g_request;
    if (!$g_request) {
        return $pa_text;
    }
    foreach ($pa_text as $vn_i => $vs_text) {
        $vs_text = preg_replace("!([A-Za-z0-9]+)='([^']*)'!", "\$1=\"\$2\"", $vs_text);
        $va_l_tags = array();
        $o_links = $o_doc('l');
        foreach ($o_links as $o_link) {
            if (!$o_link) {
                continue;
            }
            $vs_html = $o_link->html();
            $vs_content = preg_replace("!^<[^\\>]+>!", "", $vs_html);
            $vs_content = preg_replace("!<[^\\>]+>\$!", "", $vs_content);
            $va_l_tags[] = array('directive' => html_entity_decode($vs_html), 'content' => $vs_content);
            //html_entity_decode
        }
        if (sizeof($va_l_tags)) {
            $vs_content = html_entity_decode($vs_text);
            $vs_content = preg_replace_callback("/(&#[0-9]+;)/", function ($m) {
                return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
            }, $vs_content);
            foreach ($va_l_tags as $va_l) {
                if ($vb_can_handle_target) {
                    $va_params = array('request' => $g_request, 'content' => $va_l['content'], 'table' => $ps_table_name, 'id' => $pa_row_ids[$vn_i], 'classname' => $ps_class, 'target' => $ps_target, 'additionalParameters' => null, 'options' => null);
                    $va_params = $o_app_plugin_manager->hookGetAsLink($va_params);
                    $vs_link_text = $va_params['tag'];
                } else {
                    switch (__CA_APP_TYPE__) {
                        case 'PROVIDENCE':
                            $vs_link_text = caEditorLink($g_request, $va_l['content'], $ps_class, $ps_table_name, $pa_row_ids[$vn_i], $pb_add_rel ? array('rel' => true) : array());
                            break;
                        case 'PAWTUCKET':
                            $vs_link_text = caDetailLink($g_request, $va_l['content'], $ps_class, $ps_table_name, $pa_row_ids[$vn_i]);
                            break;
                    }
                }
                if ($vs_link_text) {
                    $vs_content = str_replace($va_l['directive'], $vs_link_text, $vs_content);
                } else {
                    $vs_content = str_replace($va_l['directive'], $va_l['content'], $vs_content);
                }
            }
            $va_links[] = $vs_content;
        } else {
            if (isset($pa_options['requireLinkTags']) && $pa_options['requireLinkTags']) {
                $va_links[] = $vs_text;
                continue;
            }
            if ($vb_can_handle_target) {
                $va_params = array('request' => $g_request, 'content' => $vs_text, 'table' => $ps_table_name, 'id' => $pa_row_ids[$vn_i], 'classname' => $ps_class, 'target' => $ps_target, 'additionalParameters' => null, 'options' => null);
                $va_params = $o_app_plugin_manager->hookGetAsLink($va_params);
                $va_links[] = $va_params['tag'];
            } else {
                switch (__CA_APP_TYPE__) {
                    case 'PROVIDENCE':
                        $va_links[] = ($vs_link = caEditorLink($g_request, $vs_text, $ps_class, $ps_table_name, $pa_row_ids[$vn_i])) ? $vs_link : $vs_text;
                        break;
                    case 'PAWTUCKET':
                        $va_links[] = ($vs_link = caDetailLink($g_request, $vs_text, $ps_class, $ps_table_name, $pa_row_ids[$vn_i])) ? $vs_link : $vs_text;
                        break;
                    default:
                        $va_links[] = $vs_text;
                        break;
                }
            }
//.........这里部分代码省略.........
开发者ID:samrahman,项目名称:providence,代码行数:101,代码来源:displayHelpers.php

示例14: getSaldo

 function getSaldo($uid)
 {
     curl_setopt($this->ch, CURLOPT_POST, 0);
     curl_setopt($this->ch, CURLOPT_URL, self::SALDO_URL . "?uid=" . $uid);
     //execute the request
     $content = curl_exec($this->ch);
     //echo "JES--->".$content;
     //parse html
     $html = str_get_dom($content);
     $tituloPantalla = utf8_encode($html("p[class='header2']", 0)->getInnerText());
     //$tituloPantalla = $html("p[class='header2']",0)->html();
     $pieces = explode(" ", $tituloPantalla);
     //$nombre = str_replace("de\u00a0", "", $pieces[3]);
     $nombre = substr($pieces[3], 4);
     // 			$nombre = $pieces[3];
     $apellido = $pieces[4];
     $ingresos = $html("td[class='textsmall']", 1)->getInnerText();
     $compras = $html("td[class='textsmall']", 2)->getInnerText();
     $gastos = $html("td[class='textsmall']", 3)->getInnerText();
     $tasa = $html("td[class='textsmall']", 4)->getInnerText();
     $saldo = $html("td[class='textsmall']", 5)->firstChild()->getInnerText();
     //echo "JES-->saldo-->".$saldo->getInnerText();
     $porcentaje_ventas = $html("td[class='textsmall']", 6)->getInnerText();
     $porcentaje_compras = $html("td[class='textsmall']", 7)->getInnerText();
     $ventas_compras = $html("td[class='textsmall']", 8)->getInnerText();
     $ingresos_gastos = $html("td[class='textsmall']", 9)->getInnerText();
     $intercambios = $html("td[class='textsmall']", 10)->getInnerText();
     $total = $html("td[class='textsmall']", 11)->getInnerText();
     $venta_media = $html("td[class='textsmall']", 12)->getInnerText();
     $compra_media = $html("td[class='textsmall']", 13)->getInnerText();
     $limite_positivo = $html("td[class='textsmall']", 14)->getInnerText();
     $limite_negativo = $html("td[class='textsmall']", 15)->getInnerText();
     $excedido_limite = $html("td[class='textsmall']", 16)->getInnerText();
     $indicador = $html("td[class='textsmall']", 17)->getInnerText();
     $primer_intercambio = $html("td[class='textsmall']", 18)->getInnerText();
     $ultima_venta = $html("td[class='textsmall']", 19)->getInnerText();
     if (strpos($ultima_venta, 'None') === false) {
         $pieces = explode(" ", $ultima_venta);
         $ultima_venta = $pieces[0] . " " . $this->month_es_ES[$pieces[1]] . " " . $pieces[2];
     } else {
         $ultima_venta = "Ninguna";
     }
     $ultima_compra = $html("td[class='textsmall']", 20)->getInnerText();
     if (strpos($ultima_compra, 'None') === false) {
         $pieces = explode(" ", $ultima_compra);
         $ultima_compra = $pieces[0] . " " . $this->month_es_ES[$pieces[1]] . " " . $pieces[2];
     } else {
         $ultima_compra = "Ninguna";
     }
     $result = array("nombre" => $nombre, "apellido" => $apellido, "saldo" => $saldo, "intercambios" => $intercambios, "ultimaVenta" => $ultima_venta, "ultimaCompra" => $ultima_compra);
     return json_encode($result);
 }
开发者ID:jescacena,项目名称:cispAPI,代码行数:52,代码来源:class.CesGateway.inc.php

示例15: get_request_loc

    public function get_request_loc($name, $code, $ref, $post_params) {
        $login_resp = $this->login($name, $code);
        
        # We want to both submit to and use this URL as the referrer
        $url = $this->catalog_url . $ref;

        $body = http_request_body_encode($post_params, array());

        $resp = http_parse_message(http_post_data(
            $url, $body, array(
                "cookies"    => $login_resp['cookies'],
                "referer"    => $url,
            )
        ));

        $html = str_get_dom($resp->body);

        $locs   = $this->find_request_loc($html);
        $hidden = $this->find_hidden_fields($html); 
        
        $resp = array(
            "locs"    => $locs,
            "hidden"  => $hidden,
        );

        return $resp;
    }
开发者ID:hopkinsju,项目名称:MobileCat,代码行数:27,代码来源:IIIParse.php


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