本文整理汇总了PHP中DOMDocument::loadhtml方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::loadhtml方法的具体用法?PHP DOMDocument::loadhtml怎么用?PHP DOMDocument::loadhtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::loadhtml方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCountries
protected function getCountries()
{
$xe = $this->web->get(sfConfig::get('app_source_countries'), null, array('Cache-Control' => 'no-cache'));
$doc = new DOMDocument();
// It's rare you'll have valid XHTML, suppress any errors- it'll do its best.
@$doc->loadhtml($xe->getResponseText());
$xpath = new DOMXPath($doc);
foreach ($xpath->query('/html/body//form//select[@name="From"]')->item(0)->getElementsByTagName('option') as $option) {
$currency = Doctrine::getTable('Currency')->findOneByCode($option->getAttribute('value'));
$name = substr($option->textContent, 0, strpos($option->textContent, ','));
if ($currency instanceof Currency && !empty($name)) {
$country = Doctrine::getTable('Country')->findOneByName($name);
if (!$country instanceof Country) {
$country = new Country();
$country->setName($name);
}
$country->Currencies[] = $currency;
$country->save();
}
}
}
示例2: listen
/**
* Receive ping, check if local page is pingback-enabled, verify
* source contents, and return XML-RPC response
* @return string
* @param $func callback
* @param $path string
**/
function listen($func, $path = NULL)
{
$fw = \Base::instance();
if (PHP_SAPI != 'cli') {
header('X-Powered-By: ' . $fw->get('PACKAGE'));
header('Content-Type: application/xml; ' . 'charset=' . ($charset = $fw->get('ENCODING')));
}
if (!$path) {
$path = $fw->get('BASE');
}
$web = \Web::instance();
$args = xmlrpc_decode_request($fw->get('BODY'), $method, $charset);
$options = array('encoding' => $charset);
if ($method == 'pingback.ping' && isset($args[0], $args[1])) {
list($source, $permalink) = $args;
$doc = new \DOMDocument('1.0', $fw->get('ENCODING'));
// Check local page if pingback-enabled
$parts = parse_url($permalink);
if ((empty($parts['scheme']) || $parts['host'] == $fw->get('HOST')) && preg_match('/^' . preg_quote($path, '/') . '/' . ($fw->get('CASELESS') ? 'i' : ''), $parts['path']) && $this->enabled($permalink)) {
// Check source
$parts = parse_url($source);
if ((empty($parts['scheme']) || $parts['host'] == $fw->get('HOST')) && ($req = $web->request($source)) && $doc->loadhtml($req['body'])) {
$links = $doc->getelementsbytagname('a');
foreach ($links as $link) {
if ($link->getattribute('href') == $permalink) {
call_user_func_array($func, array($source, $req['body']));
// Success
die(xmlrpc_encode_request(NULL, $source, $options));
}
}
// No link to local page
die(xmlrpc_encode_request(NULL, 0x11, $options));
}
// Source failure
die(xmlrpc_encode_request(NULL, 0x10, $options));
}
// Doesn't exist (or not pingback-enabled)
die(xmlrpc_encode_request(NULL, 0x21, $options));
}
// Access denied
die(xmlrpc_encode_request(NULL, 0x31, $options));
}
示例3: LoadDomFromHTML
public function LoadDomFromHTML($strHTML)
{
// $oDOM = new DOMDocument( '1.0', $this->strCharEncoding );
$oDOM = new DOMDocument('1.0');
// $oDOM->preserveWhiteSpace = false;
// $oDOM->formatOutput = true;
// $strHTML = '<div>' . $strHTML . '</div>'; // this prevents later when using saveXML() from inserting the comment <!-- xml version .... -->
$oDOM->loadhtml($strHTML);
return $oDOM;
}
示例4: changeLinks
/**
* Changes the links (src/href) of HTML
* @return: String
*/
public function changeLinks($contents, $root_path = JPATH_ROOT, $base_uri = '')
{
/** change js links **/
$regex = '/src=(["\'])(.*?)\\1/';
$count = preg_match_all($regex, $contents, $match);
if ($count > 0) {
$changes = $match[2];
foreach ($changes as $change) {
//remove url file not exists
$uri = new JURI($change);
if ($_SERVER['HTTP_HOST'] != $uri->getHost() && $uri->getHost() != '') {
$headers = @get_headers($change, 1);
if ($headers[0] == 'HTTP/1.1 404 Not Found') {
$contents = str_replace('src="' . $change . '"', 'src=""', $contents);
}
}
}
}
/** change href reference **/
$regex = '/href=(["\'])(.*?)\\1/';
$count = preg_match_all($regex, $contents, $match);
if ($count > 0) {
$changes = $match[2];
foreach ($changes as $change) {
//remove url file not exists
$uri = new JURI($change);
if ($_SERVER['HTTP_HOST'] != $uri->getHost() && $uri->getHost() != '') {
$headers = @get_headers($change, 1);
if ($headers[0] == 'HTTP/1.1 404 Not Found') {
$contents = str_replace('href="' . $change . '"', 'href=""', $contents);
}
}
}
}
/** change href reference **/
$regex = '/action=(["\'])(.*?)\\1/';
$count = preg_match_all($regex, $contents, $match);
if ($count > 0) {
$changes = $match[2];
foreach ($changes as $change) {
//remove url file not exists
$uri = new JURI($change);
if ($_SERVER['HTTP_HOST'] != $uri->getHost() && $uri->getHost() != '') {
$headers = @get_headers($change, 1);
if ($headers[0] == 'HTTP/1.1 404 Not Found') {
$contents = str_replace('action="' . $change . '"', 'action=""', $contents);
}
}
}
}
/** change links **/
$doc = new DOMDocument();
if (@$doc->loadhtml($contents)) {
$xpath = new DOMXpath($doc);
$uri = JURI::getInstance();
foreach ($xpath->query('//html//a') as $eInput) {
$href = $eInput->getAttribute('href');
$uri = new JURI($href);
if (JString::trim($href) != '#' && JString::trim($href) != '' && ($_SERVER['HTTP_HOST'] == $uri->getHost() || $uri->getHost() == '')) {
$extend_url = JSN_RENDER_PAGE_URL . base64_encode($href);
$eInput->setAttribute('href', $extend_url);
} else {
$eInput->setAttribute('href', 'javascript:;');
}
}
}
/** SAVE HTML after changed **/
return $doc->saveHTML();
}
示例5: getCurrentItemid
/**
* Get Current Menu Id.
*
* @return integer
*/
public function getCurrentItemid()
{
$doc = new DOMDocument();
if (@$doc->loadhtml($this->_contents)) {
$doc->preserveWhiteSpace = false;
$component = $doc->getElementById('tableshow');
if (is_object($component)) {
return $component->getAttribute('itemid');
}
}
return 0;
}