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


PHP validate::url方法代码示例

本文整理汇总了PHP中validate::url方法的典型用法代码示例。如果您正苦于以下问题:PHP validate::url方法的具体用法?PHP validate::url怎么用?PHP validate::url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在validate的用法示例。


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

示例1: parse

 /**
  * Parses a remote feed into an array.
  *
  * @param   string   remote feed URL
  * @param   integer  item limit to fetch
  * @return  array
  */
 public static function parse($feed, $limit = 0)
 {
     // Check if SimpleXML is installed
     if (!function_exists('simplexml_load_file')) {
         throw new Kohana_Exception('SimpleXML must be installed!');
     }
     // Make limit an integer
     $limit = (int) $limit;
     // Disable error reporting while opening the feed
     $ER = error_reporting(0);
     // Allow loading by filename or raw XML string
     $load = (is_file($feed) or validate::url($feed)) ? 'simplexml_load_file' : 'simplexml_load_string';
     // Load the feed
     $feed = $load($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
     // Restore error reporting
     error_reporting($ER);
     // Feed could not be loaded
     if ($feed === FALSE) {
         return array();
     }
     // Detect the feed type. RSS 1.0/2.0 and Atom 1.0 are supported.
     $feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry;
     $i = 0;
     $items = array();
     foreach ($feed as $item) {
         if ($limit > 0 and $i++ === $limit) {
             break;
         }
         $items[] = (array) $item;
     }
     return $items;
 }
开发者ID:Normull,项目名称:core,代码行数:39,代码来源:feed.php

示例2: __construct

	/**
	 * Class constructor. You should use the factory instead.
	 * @param string $element [optional] What to construct from. Could be some xml string, a file name, or a DOMNode
	 * @param string $root_node [optional] The root node name. To be specified if no driver are used.
	 * @return XML XML object instance
	 */
	public function __construct($element = NULL, $root_node = NULL)
	{
		// Create the initial DOMDocument
		$this->dom_doc = new DOMDocument(XML::$xml_version, Kohana::$charset);

		if ($root_node)
		{
			// If a root node is specified, overwrite the current_one
			$this->root_node = $root_node;
		}

		// Initialize the document with the given element
		if (is_string($element))
		{
			if (is_file($element) OR validate::url($element))
			{
				// Generate XML from a file
				$this->dom_doc->load($element);
			}
			else
			{
				// Generate XML from a string
				$this->dom_doc->loadXML($element);
			}
			// Node is the root node of the document, containing the whole tree
			$this->dom_node = $this->dom_doc->documentElement;
		}
		elseif ($element instanceof DOMNode)
		{
			// This is called from another XML instance ( through add_node, or else...)
			// Let's add that node to the new object node 
			$this->dom_node = $element;

			// And overwrite the document with that node's owner document
			$this->dom_doc = $this->dom_node->ownerDocument;
		}
		elseif ( ! is_null($this->root_node))
		{
			// Create the Root Element from the driver attributes
			if ($this->meta()->ns($this->root_node))
			{
				list($ns, $prefix) = $this->meta()->ns($this->root_node);
				
				$root_node_name = $prefix ? "$prefix:$this->root_node" : $this->root_node;
				
				// Create the root node in its prefixed namespace
				$root_node = $this->dom_doc->createElementNS($ns, $root_node_name);
			}
			else
			{
				// Create the root node
				$root_node = $this->dom_doc->createElement($this->root_node);
			}
			
			// Append the root node to the object DOMDocument, and set the resulting DOMNode as it's node
			$this->dom_node = $this->dom_doc->appendChild($root_node);
			
			// Add other attributes
			$this->add_attributes($this->dom_node);
		}
		else
		{
			throw new Kohana_Exception("You have to specify a root_node, either in your driver or in the constructor if you're not using any.");
		}
	}
开发者ID:refo,项目名称:kohana,代码行数:71,代码来源:core.php

示例3: default_image

 /**
  * Accessor method for setting the default image if the supplied email address or rating return an empty result
  *
  * @param   string       url  the url of the image to use instead of the Gravatar
  * @return  self
  */
 public function default_image($url = NULL)
 {
     if ($url === NULL) {
         return $this->_config['default'];
     } else {
         if (validate::url($url)) {
             $this->_config['default'] = $url;
         } else {
             throw new Gravatar('The url : :url is improperly formatted', array(':url' => $url));
         }
     }
     return $this;
 }
开发者ID:samsoir,项目名称:kohana-gravatar,代码行数:19,代码来源:gravatar.php


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