New version submitted by TomB
[carbonphp.git] / Documentation / utilities / url.html
blob053f4d926e61b28d1d452e70074921cc1c82dfaa
1 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
2 <head>
3 <title>CarbonPHP Documentation</title>
4 <style type="text/css">
5 * {
6 margin: 0;
7 padding: 0;
10 a, a:hover {
11 background: transparent;
12 border-bottom: 1px dotted #666;
13 color: #666;
14 text-decoration: none;
17 a:hover {
18 border: 0;
21 html {
22 font-family: "Lucida Sans Unicode", "Lucida Grande";
23 font-size: 14px;
26 body {
27 background: #fff;
28 color: #666;
31 h1 {
32 font-size: 15px;
33 font-weight: bold;
34 margin: 0 0 5px 0;
37 h2 {
38 font-size: 13px;
39 font-weight: bold;
40 margin: 5px 0 5px 0;
43 ol, ul {
44 margin: 10px 0 10px 0;
45 list-style-position: inside;
48 p {
49 margin: 5px 0 5px 0;
52 .content {
53 border: 1px dotted #444;
54 margin: 10px;
55 padding: 10px;
56 text-align: justify;
57 width: 700px;
60 .example {
61 border: 1px solid #ccc;
62 background: #eee;
63 margin: 10px;
64 padding: 10px;
65 text-align: left;
67 </style>
68 </head>
70 <body>
71 <div class="content">
72 <h1>URL Utility</h1>
74 <p>This utility file contains functions to help with working with URLs. You can load this utility using
75 the following piece of code.</p>
77 <div class="example">
78 $this->load->utility('url');
79 </div>
80 </div>
82 <div class="content">
83 <h1>site_url()</h1>
85 <p>This function returns the site URL as specified in your config file. The index.php file will be
86 added to the URL, as will any URI segments you pass to the function.</p>
88 <div class="example">
89 echo site_url('blog/post/1');
90 </div>
92 <p>The above example would return something like the following.</p>
94 <div class="example">
95 www.your-domain.com/index.php/blog/post/1
96 </div>
98 <p>You can also pass the segments as an array.</p>
100 <div class="example">
101 $segments = array('blog', 'post', '1');<br />
102 <br />
103 echo site_url($segments);
104 </div>
105 </div>
107 <div class="content">
108 <h1>base_url()</h1>
110 <p>This function returns the site base URL as specified in the configuration file.</p>
111 </div>
113 <div class="content">
114 <h1>index_page()</h1>
116 <p>This function returns the site index page as specified in your configuration file.</p>
117 </div>
119 <div class="content">
120 <h1>anchor()</h1>
122 <p>This function creates a standard HTML anchor link based on your site URL.</p>
124 <p>The first parameter can contain any segments you wish to append to the URL. As with the <b>site_url()</b>
125 function above, segments can be a string, or an array. The second segment is the text you would like the
126 link to say. If you leave it blank, the URL will be used. The third parameter can contain a list of
127 attributes you would like added to the link.</p>
129 <div class="example">
130 echo anchor('news/local/1', 'Local News');
131 </div>
133 <div class="example">
134 echo anchor('news/local/1', 'Local News', array('title' => 'Local News'));
135 </div>
136 </div>
138 <div class="content">
139 <h1>anchor_popup()</h1>
141 <p>This function is nearly identical to the <b>anchor()</b> function except that it opens the URL in a new
142 window. You can specify the JavaScript window attributes in the third parameter to control how the window
143 is opened.</p>
145 <div class="example">
146 $attr = array(<br />
147 &nbsp;&nbsp;&nbsp;&nbsp;'width' => '800',<br />
148 &nbsp;&nbsp;&nbsp;&nbsp;'height' => '600',<br />
149 &nbsp;&nbsp;&nbsp;&nbsp;'scrollbars' => 'yes',<br />
150 &nbsp;&nbsp;&nbsp;&nbsp;'status' => 'yes',<br />
151 &nbsp;&nbsp;&nbsp;&nbsp;'resizable' => 'yes',<br />
152 &nbsp;&nbsp;&nbsp;&nbsp;'screenx' => '0',<br />
153 &nbsp;&nbsp;&nbsp;&nbsp;'screeny' => '0'<br />
154 );<br />
155 <br />
156 echo anchor_popup('news/local/1', 'Local News', $attr);
157 </div>
159 <p>If you wish to use the function default you only need to pass an empty array to the third parameter.</p>
160 </div>
162 <div class="content">
163 <h1>mailto()</h1>
165 <p>This function creates a standard HTML email link.</p>
167 <div class="example">
168 echo mailto('email@domain.com', 'Contact Us');
169 </div>
171 <p>You can passed attributes using the third parameter like the <b>anchor()</b> function.</p>
172 </div>
174 <div class="content">
175 <h1>safe_mailto()</h1>
177 <p>This function is identical to the <b>mailto()</b> function except it writes an obfuscated version of
178 the mailto tag with ordinal numbers written with JavaScript.</p>
179 </div>
181 <div class="content">
182 <h1>auto_link()</h1>
184 <p>This function automatically turns URLs and email addresses contained in a string into links.</p>
186 <div class="example">
187 $string = auto_link($string);
188 </div>
190 <p>The second parameter determines whether URLs and emails are converted or just one or the other.</p>
192 <p>Converting only URLs.</p>
194 <div class="example">
195 $string = auto_link($string, 'url');
196 </div>
198 <p>Converting only emails.</p>
200 <div class="example">
201 $string = auto_link($string, 'email');
202 </div>
204 <p>The third parameter determines whether links are shown in a new window.</p>
206 <div class="example">
207 $string = auto_link($string, 'both', true);
208 </div>
209 </div>
211 <div class="content">
212 <h1>url_title()</h1>
214 <p>This function takes a string as input and creates a human friendly URL string.</p>
216 <div class="example">
217 $title = "What's Wrong With HTML";<br />
218 <br />
219 $url_title = url_title($title);<br />
220 <br />
221 // This produces: whats-wrong-with-html
222 </div>
224 <p>The second parameter determines the character for the word delimeter. The options are <b>dash</b> or
225 <b>underscore</b>.</p>
227 <div class="example">
228 $title = "What's Wrong With HTML";<br />
229 <br />
230 $url_title = url_title($title, 'underscore');<br />
231 <br />
232 // This produces: whats_wrong_with_html
233 </div>
234 </div>
236 <div class="content">
237 <h1>prep_url()</h1>
239 <p>This function will add <b>http://</b> in the event that it is missing from a URL.</p>
241 <div class="example">
242 $url = "www.your-domain.com";<br />
243 <br />
244 $url = prep_url($url);
245 </div>
246 </div>
248 <div class="content">
249 <h1>redirect()</h1>
251 <p>This function does a header redirect to the local URI specified. Just like other function in this
252 utility, this one is designed to use a local URL. You do not specify the full site URL. The second parameter
253 allows you to choose between the 'location' method or the 'refresh' method.</p>
255 <div class="example">
256 if (!$logged_in)<br />
257 &#123;<br />
258 &nbsp;&nbsp;&nbsp;&nbsp;redirect('login/form', 'refresh');<br />
259 &#125;
260 </div>
262 <p>In order for this function to work correctly it must be used before any output is sent to the browser.</p>
263 </div>
264 </body>
266 </html>