Location: PHPKode > scripts > URLclass > urlclass/URL.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>Docs For Class URL</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
			<div class="page-body">			
<h2 class="class-name">Class URL</h2>

<a name="sec-description"></a>
<div class="info-box">
	<div class="info-box-title">Description</div>
	<div class="nav-bar">
					<span class="disabled">Description</span> |
															<a href="#sec-method-summary">Methods</a> (<a href="#sec-methods">details</a>)
						
			</div>
	<div class="info-box-body">
		<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">URL class intended for http and https schemes</p>
<p class="description"><p>This class allows you store absolute or relative URLs and access it's  various parts (scheme, host, port, part, query, fragment).</p><p>It will also accept and attempt to resolve a relative URL against an  absolute URL already stored.</p><p>Note: this URL class is based on the HTTP scheme.</p><p>Example:  <pre><br />1        <span class="src-var">$url</span> =<span class="src-sym">&amp;</span> <span class="src-key">new</span> <a href="../HTTP_Navigator_2/URL.html#methodURL">URL</a><span class="src-sym">(</span><span class="src-str">'http://www.domain.com/path/file.php?query=blah'</span><span class="src-sym">)</span>;<br />2        echo <span class="src-var">$url</span><span class="src-sym">-&gt;</span><a href="../HTTP_Navigator_2/URL.html#methodget_scheme">get_scheme</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span><span class="src-str">&quot;\n&quot;</span>;    <span class="src-comm">// http</span><br />3        echo <span class="src-var">$url</span><span class="src-sym">-&gt;</span><a href="../HTTP_Navigator_2/URL.html#methodget_host">get_host</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span><span class="src-str">&quot;\n&quot;</span>;      <span class="src-comm">// www.domain.com</span><br />4        echo <span class="src-var">$url</span><span class="src-sym">-&gt;</span><a href="../HTTP_Navigator_2/URL.html#methodget_path">get_path</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span><span class="src-str">&quot;\n&quot;</span>;      <span class="src-comm">// /path/file.php</span><br />5        echo <span class="src-var">$url</span><span class="src-sym">-&gt;</span><a href="../HTTP_Navigator_2/URL.html#methodget_query">get_query</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span><span class="src-str">&quot;\n&quot;</span>;     <span class="src-comm">// query=blah</span><br />6        <span class="src-comm">// Setting a relative URL against our existing URL</span><br />7        <span class="src-var">$url</span><span class="src-sym">-&gt;</span><a href="../HTTP_Navigator_2/URL.html#methodset_relative">set_relative</a><span class="src-sym">(</span><span class="src-str">'../great.php'</span><span class="src-sym">)</span>;<br />8        echo <span class="src-var">$url</span><span class="src-sym">-&gt;</span><a href="../HTTP_Navigator_2/URL.html#methodas_string">as_string</a><span class="src-sym">(</span><span class="src-sym">)</span>; </pre></p><p>See test_URL.php file for examples of how relative URLs are handled.</p><p>CHANGES: <ul><li>0.3 (15-Jul-2003)
    - equal_to() method added.</li><li>0.2 (30-Dec-2002)
    - Class name changed from Url to URL.
    - Added $use_default param to the get_port() method.
    - Added clone() method.
    - Added as_string() method, which is what I should've had instead of get()
    - Added parameter to as_string() method: $include_fragment (default: true),
      passing false to as_string() will omit the fragment and crosshatch ('#')
      from the URL</li><li>0.1
    - Initial release</li></ul> TODO: <ul><li>modify set_relative() to accept URL objects as well as strings</li></ul></p></p>
	<ul class="tags">
				<li><span class="field">version:</span> <p>0.3</p></li>
				<li><span class="field">author:</span> <p>Keyvan Minoukadeh &lt;<a href="mailto:hide@address.com">mailto:hide@address.com</a>&gt;</p></li>
			</ul>
		<p class="notes">
			Located in <a class="field" href="_classes_URL_php.html">Program_Root/URL.php</a> (line <span class="field"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a69">69</a></span>)
		</p>
		
				
		<pre></pre>
	
			</div>
</div>



	<a name="sec-method-summary"></a>
	<div class="info-box">
		<div class="info-box-title">Method Summary</span></div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
									<span class="disabled">Methods</span> (<a href="#sec-methods">details</a>)
		</div>
		<div class="info-box-body">			
			<div class="method-summary">
								
				<div class="method-definition">
											<span class="method-result">void</span>
										<a href="#URL" title="details" class="method-name">URL</a>
											([<span class="var-type">string</span>&nbsp;<span class="var-name">$url</span> = <span class="var-default">null</span>])
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#as_string" title="details" class="method-name">as_string</a>
											([<span class="var-type">mixed</span>&nbsp;<span class="var-name">$fragment</span> = <span class="var-default">URL_OPTION_WITH_FRAG</span>], <span class="var-type">int</span>&nbsp;<span class="var-name">$option</span>)
									</div>
								
				<div class="method-definition">
											<span class="method-result">object</span>
										<a href="#clone" title="details" class="method-name">&amp;clone</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">bool</span>
										<a href="#equal_to" title="details" class="method-name">equal_to</a>
											(<span class="var-type">mixed</span>&nbsp;<span class="var-name">$url</span>)
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get" title="details" class="method-name">get</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get_fragment" title="details" class="method-name">get_fragment</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get_host" title="details" class="method-name">get_host</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get_pass" title="details" class="method-name">get_pass</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get_path" title="details" class="method-name">get_path</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get_path_query" title="details" class="method-name">get_path_query</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">int</span>
										<a href="#get_port" title="details" class="method-name">get_port</a>
											([<span class="var-type">bool</span>&nbsp;<span class="var-name">$use_default</span> = <span class="var-default">false</span>])
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get_query" title="details" class="method-name">get_query</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get_scheme" title="details" class="method-name">get_scheme</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">string</span>
										<a href="#get_user" title="details" class="method-name">get_user</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">bool</span>
										<a href="#is_absolute" title="details" class="method-name">is_absolute</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">bool</span>
										<a href="#is_relative" title="details" class="method-name">is_relative</a>
										()
									</div>
								
				<div class="method-definition">
											<span class="method-result">void</span>
										<a href="#set" title="details" class="method-name">set</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$url</span>)
									</div>
								
				<div class="method-definition">
											<span class="method-result">void</span>
										<a href="#set_relative" title="details" class="method-name">set_relative</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$url</span>)
									</div>
							</div>
		</div>
	</div>		

	
	<a name="sec-methods"></a>
	<div class="info-box">
		<div class="info-box-title">Methods</div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
													<a href="#sec-method-summary">Methods</a> (<span class="disabled">details</span>)
						
		</div>
		<div class="info-box-body">
			<A NAME='method_detail'></A>
<a name="methodURL" id="URL"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">Constructor URL</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a141">141</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Constructor</p>
<p class="description"><p>Optional parameter accepts a URL string</p></p>
	
	<div class="method-signature">
		<span class="method-result">void</span>
		<span class="method-name">
			URL
		</span>
					([<span class="var-type">string</span>&nbsp;<span class="var-name">$url</span> = <span class="var-default">null</span>])
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$url</span>			</li>
				</ul>
		
		
	</div>
<a name="methodas_string" id="as_string"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">as_string</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a340">340</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">As string</p>
<p class="description"><p>Returns the full URL (excluding any user info).  Optional parameter allows you to specify whether you want the fragment (if available)  to be included (default behaviour) in the resulting URL, or omitted.  Passing false to as_string() will omit the fragment and crosshatch ('#') from the returned  result.</p></p>
	<ul class="tags">
				<li><span class="field">since:</span> <p>0.2</p></li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			as_string
		</span>
					([<span class="var-type">mixed</span>&nbsp;<span class="var-name">$fragment</span> = <span class="var-default">URL_OPTION_WITH_FRAG</span>], <span class="var-type">int</span>&nbsp;<span class="var-name">$option</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">int</span>
				<span class="var-name">$option</span><span class="var-description">: <p>URL_OPTION_WITH_FRAG (default) or URL_OPTION_NO_FRAG</p></span>			</li>
				</ul>
		
		
	</div>
<a name="methodclone" id="clone"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">clone</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a173">173</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Clone</p>
<p class="description"><p>Example:  <pre><br />1        <span class="src-var">$url_copy</span> =<span class="src-sym">&amp;</span> <span class="src-var">$url</span><span class="src-sym">-&gt;</span><a href="../HTTP_Navigator_2/URL.html#methodclone">clone</a><span class="src-sym">(</span><span class="src-sym">)</span>;</pre></p></p>
	
	<div class="method-signature">
		<span class="method-result">object</span>
		<span class="method-name">
			&amp;clone
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodequal_to" id="equal_to"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">equal_to</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a195">195</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Equal to</p>
<p class="description"><p>Returns true if <var>$url</var> is equal to current URL object.  I'm hoping this method reflects RFC 2616 Section 3.2.3</p><p>Note: this method will not compare the following: <ul><li>user info (username and password)</li><li>fragment (#fragment)</li></ul></p></p>
	
	<div class="method-signature">
		<span class="method-result">bool</span>
		<span class="method-name">
			equal_to
		</span>
					(<span class="var-type">mixed</span>&nbsp;<span class="var-name">$url</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">mixed</span>
				<span class="var-name">$url</span><span class="var-description">: <p>string URL or instance of URL class</p></span>			</li>
				</ul>
		
		
	</div>
<a name="methodget" id="get"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">get</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a323">323</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get URL</p>
<p class="description"><p>Returns the full URL (excluding any user info).</p></p>
	<ul class="tags">
				<li><span class="field">see:</span> <a href="../HTTP_Navigator_2/URL.html#methodas_string">URL::as_string()</a></li>
				<li><span class="field">deprecated:</span> <p>deprecated since version 0.2, use as_string() method instead.</p></li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodget_fragment" id="get_fragment"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">get_fragment</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a501">501</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get fragment</p>
<p class="description"><p>Returns everything after the &quot;#&quot;, or false if no fragment was specified</p></p>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get_fragment
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodget_host" id="get_host"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">get_host</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a433">433</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get host</p>
<p class="description"><p>Returns the hostname/ip, or false if no hostname/ip was specified</p></p>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get_host
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodget_pass" id="get_pass"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">get_pass</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a422">422</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get password</p>
<p class="description"><p>Returns the password, or false if no password was specified.</p></p>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get_pass
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodget_path" id="get_path"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">get_path</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a467">467</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get path</p>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get_path
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodget_path_query" id="get_path_query"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">get_path_query</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a490">490</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get path and query</p>
<p class="description"><p>Returns the path and (if available) the query</p></p>
	<ul class="tags">
				<li><span class="field">since:</span> <p>0.2</p></li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get_path_query
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodget_port" id="get_port"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">get_port</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a450">450</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get port</p>
<p class="description"><p>Returns the port number, or false if no port was specified.</p><p>If you pass true to get_port(), a default port will be returned if no  port is found.  This is based on checking if the URL is using the HTTP  scheme (if so, 80 will be returned), or HTTPS scheme (if so, 443 will be  returned).</p></p>
	
	<div class="method-signature">
		<span class="method-result">int</span>
		<span class="method-name">
			get_port
		</span>
					([<span class="var-type">bool</span>&nbsp;<span class="var-name">$use_default</span> = <span class="var-default">false</span>])
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">bool</span>
				<span class="var-name">$use_default</span><span class="var-description">: <p>(optional) default: false</p></span>			</li>
				</ul>
		
		
	</div>
<a name="methodget_query" id="get_query"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">get_query</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a478">478</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get query</p>
<p class="description"><p>Returns everything after the &quot;?&quot;, or false if no query was specified</p></p>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get_query
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodget_scheme" id="get_scheme"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">get_scheme</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a400">400</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get scheme</p>
<p class="description"><p>Returns the scheme, or false if no scheme was specified.</p></p>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get_scheme
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodget_user" id="get_user"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">get_user</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a411">411</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Get username</p>
<p class="description"><p>Returns the username, or false if no username was specified.</p></p>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			get_user
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodis_absolute" id="is_absolute"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">is_absolute</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a377">377</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Is absolute URL</p>
<p class="description"><p>Returns true if scheme was specified</p></p>
	<ul class="tags">
				<li><span class="field">see:</span> <a href="../HTTP_Navigator_2/URL.html#methodis_relative">URL::is_relative()</a></li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">bool</span>
		<span class="method-name">
			is_absolute
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodis_relative" id="is_relative"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">is_relative</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a389">389</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Is relative URL</p>
<p class="description"><p>Opposite of is_absolute()</p></p>
	<ul class="tags">
				<li><span class="field">see:</span> <a href="../HTTP_Navigator_2/URL.html#methodis_absolute">URL::is_absolute()</a></li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">bool</span>
		<span class="method-name">
			is_relative
		</span>
				()
			</div>
	
		
		
	</div>
<a name="methodset" id="set"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">set</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a156">156</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Set URL</p>
<p class="description"><p>Will overwrite all existing URL parts (see set_relative() to set a relative URL)</p></p>
	<ul class="tags">
				<li><span class="field">see:</span> <a href="../HTTP_Navigator_2/URL.html#methodset_relative">URL::set_relative()</a></li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">void</span>
		<span class="method-name">
			set
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$url</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$url</span>			</li>
				</ul>
		
		
	</div>
<a name="methodset_relative" id="set_relative"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">set_relative</span> (line <span class="line-number"><a href="..//__filesource/fsource_HTTP_Navigator_2__URL.php.html#a250">250</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Set relative URL</p>
<p class="description"><p>Sets a URL as relative to the current URL (base).  An absolute URL passed to this method will overwrite all existing URL parts stored.  I'm hoping this method reflects RFC 2396 Section 5.2</p></p>
	
	<div class="method-signature">
		<span class="method-result">void</span>
		<span class="method-name">
			set_relative
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$url</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$url</span>			</li>
				</ul>
		
		
	</div>
						
		</div>
	</div>
	
	<p class="notes" id="credit">
		Documention generated on Wed, 16 Jul 2003 01:04:00 +0100 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.2.0</a>
	</p>
	</div></body>
</html>
Return current item: URLclass