當前位置: 首頁>>代碼示例>>PHP>>正文


PHP func::getAttributesFromString方法代碼示例

本文整理匯總了PHP中func::getAttributesFromString方法的典型用法代碼示例。如果您正苦於以下問題:PHP func::getAttributesFromString方法的具體用法?PHP func::getAttributesFromString怎麽用?PHP func::getAttributesFromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在func的用法示例。


在下文中一共展示了func::getAttributesFromString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getRemoteFeed

		function getRemoteFeed($url, $depth=0) {
			global $db;
			if($depth>3) {
				return array(2, null, null);
			}
			requireComponent('LZ.PHP.HTTPRequest');
			$request = new HTTPRequest();
			$xml = $request->getPage($url);
			if (empty($xml)) {
				return array(2, null, null);
			}
			$feed = array('xmlURL' => $url);
			
			$encoding = '';
			if (preg_match('/^<\?xml[^<]*\s+encoding=["\']?([\w-]+)["\']?/', $xml, $matches))
				$encoding = $matches[1];
			if (strcasecmp($encoding, 'utf-8') != 0) {
				$xml = UTF8::bring($xml, $encoding);
				$xml = preg_replace('/^(<\?xml[^<]*\s+encoding=)["\']?[\w-]+["\']?/', '$1"utf-8"', $xml, 1);
			}

			if(preg_match_all('/<meta[ \t].*?http-equiv\s*=\s*[\'"]?refresh.*?>/i', $xml, $matches)) { // 야후코리아 때문 ..
				foreach($matches[0] as $link) {
					$attributes = func::getAttributesFromString($link);
					if (isset($attributes['content'])) {
						$attributes = explode(';', $attributes['content']);
						$contentURL = substr($attributes[1],4);
						if(substr($contentURL,0,7) == 'http://') {
							$url = $contentURL;
						} else {
							$url = func::unionAddress($url,$contentURL);
						}
						if(!empty($url)) {
							return Feed::getRemoteFeed($url, ++$depth);
						}
					}
				}
			}

			$xmls = new XMLStruct();
			if (!$xmls->open($xml)) {
				if(preg_match_all('/<link .*?rel\s*=\s*[\'"]?alternate.*?>/i', $xml, $matches)) {
					foreach($matches[0] as $link) {
						$attributes = func::getAttributesFromString($link);
						if (isset($attributes['href'])) {
							$urlInfo = parse_url($url);
							$rssInfo = parse_url($attributes['href']);
							$rssURL = false;
							if (isset($rssInfo['scheme']) && $rssInfo['scheme'] == 'http')
								$rssURL = $attributes['href'];
							else if (isset($rssInfo['path'])) {
								if ($rssInfo['path']{0} == '/')
									$rssURL = "{$urlInfo['scheme']}://{$urlInfo['host']}{$rssInfo['path']}";							
								else
									$rssURL = "{$urlInfo['scheme']}://{$urlInfo['host']}".(isset($urlInfo['path']) ? rtrim($urlInfo['path'], '/') : '').'/'.$rssInfo['path'];
							}
							if ($rssURL && $url != $rssURL)
								return Feed::getRemoteFeed($rssURL);
						}
					}
				}		
				return array(3, null, null);
			}

			$xmlType = '';
			$feed['blogTool'] = Func::isWhatBlog($url);
			if ($xmls->getAttribute('/rss', 'version')) {	
				$xmlType = 'rss';
				$feed['blogURL'] = $xmls->getValue('/rss/channel/link');
				$feed['title'] = $xmls->getValue('/rss/channel/title');
				$feed['description'] = $xmls->getValue('/rss/channel/description');
				if (Validator::language($xmls->getValue('/rss/channel/language')))
					$feed['language'] = $xmls->getValue('/rss/channel/language');
				else if (Validator::language($xmls->getValue('/rss/channel/dc:language')))
					$feed['language'] = $xmls->getValue('/rss/channel/dc:language');
				else
					$feed['language'] = 'en-US';
				$feed['modified'] = gmmktime();
				$feed['logo'] = $xmls->getValue('/rss/channel/image/url');
			} else if ($xmls->doesExist('/feed')) {
				$xmlType = 'atom';
				$feed['blogURL'] = $xmls->getAttribute('/feed/link', 'href');
				$feed['title'] = $xmls->getValue('/feed/title');
				if (!$feed['description'] = $xmls->getValue('/feed/tagline'))
					$feed['description'] = $xmls->getValue('/feed/subtitle');
				if (Validator::language($xmls->getAttribute('/feed', 'xml:lang')))
					$feed['language'] = $xmls->getAttribute('/feed', 'xml:lang');
				else
					$feed['language'] = 'en-US';
				$feed['modified'] = gmmktime();
			} else if ($xmls->getAttribute('/rdf:RDF', 'xmlns')) {
				$xmlType = 'rss';
				if ($xmls->getAttribute('/rdf:RDF/channel/link', 'href'))
					$feed['blogURL'] = $xmls->getAttribute('/rdf:RDF/channel/link', 'href');
				else if ($xmls->getValue('/rdf:RDF/channel/link'))
					$feed['blogURL'] = $xmls->getValue('/rdf:RDF/channel/link');
				else
					$feed['blogURL'] = '';
				$feed['title'] = $xmls->getValue('/rdf:RDF/channel/title');
				$feed['description'] = $xmls->getValue('/rdf:RDF/channel/description');
//.........這裏部分代碼省略.........
開發者ID:ncloud,項目名稱:bloglounge,代碼行數:101,代碼來源:LZ.PHP.Feeder.php


注:本文中的func::getAttributesFromString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。