-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathexample.php
More file actions
379 lines (368 loc) · 17.5 KB
/
example.php
File metadata and controls
379 lines (368 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?php
/************************************************************\
*
* wordCloud Copyright 2007 Derek Harvey
* www.lotsofcode.com
*
* This file is part of wordCloud.
*
* wordCloud is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wordCloud is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with wordCloud; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\************************************************************/
require 'classes/wordcloud.class.php';
?>
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<title>PHP wordCloud by LotsOfCode.com</title>
<style type="text/css">
<!--
@import url('./css/example.css');
@import url('./css/wordcloud.css');
textarea:before {
content: '[code]';
}
textarea:after {
content: '[/code]';
}
//-->
</style>
<script>
window.onload = function()
{
// WRITTEN BY DEL
// lotsofcode.com
// Get the elements of the main "cloud" form
e = document.forms['cloud'].elements;
// Get the length of all the elements
l = e.length;
for (var i = 0; i < l; i++) {
// If the element is a textarea
if (e[i].type == 'textarea') {
// select the element as we click on it
e[i].onclick = e[i].select;
}
}
}
</script>
</head>
<body>
<div id="example">
<form name="cloud">
<h1><a href="http://www.lotsofcode.com/php/tutorials/tag-cloud-v2" target="_blank">PHP Tag Cloud v2.0</a></h1>
<h2><a href="http://www.lotsofcode.com" target="_blank">lotsofcode.com</a></h2>
<p>Thank you for downloading the tag cloud script at lotsofcode.com, below are some examples of how you can impliment the tag cloud in to your personal website, it's pretty simple to include however if you do have any problems, please don't hesitate to use our <a href="http://www.lotsofcode.com/forum/index.php?c=3" target="_blank">support forum</a>. Good luck and i hope you find this code useful.</p>
<p>Some of the new features included in the tag cloud script are:
<ul>
<li>Link and URL Assignment to each Tag</li>
<li>Additional attribute assignment to each tag e.g. title, etc</li>
<li>Add styles and colour options to any tag</li>
<li>Set a limit to the amount of tags that are displayed</li>
<li>Examples of intergrating with a MySQL Database </li>
<li>Examples of intergrating with a Flat Text File </li>
<li>String to cloud, parse a single string into a tag cloud instantly</li>
<li>Ignore list, to remove particular words from the cloud. e.g. and, the, it, i</li>
<li>Ordering by a selective field. e.g. word, size, colour</li>
</ul>
</p>
<p><b>Important:</b> Please include the wordcloud class and the wordcloud stylesheet along with every example to get the desired results, like so:<br /><br />
<code style="padding: 4px; display: block; background: #FFF; border: 1px inset #000;">
<?php<br />
include './classes/wordcloud.class.php';<br />
?><br />
<link rel="stylesheet" href="./css/wordcloud.css" type="text/css">
</code></p>
</p>
<!-- b: basic example -->
<h3>Basic Example</h3>
<p>This is a basic example of how you can impliment a tag-cloud into your website</p>
<div class="word-cloud">
<?php
// Initite the basic object
$cloud = new wordCloud();
// Basic Add Option
$cloud->addWord('php');
$cloud->addWord('google');
$cloud->addWord('digg');
$cloud->addWord('lotsofcode');
// Advanced Add Option
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com'));
$cloud->addWord(array('word' => 'google', 'size' => 1, 'url' => 'http://www.lotsofcode.com'));
echo $cloud->showCloud();
?>
<br /><br />
</div>
<h4>Code Example</h4>
<textarea><?php
$cloud = new wordCloud();
$cloud->addWord('php'); // Basic Method of Adding Keyword
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com')); // Advanced user method
$cloud->addWord(array('word' => 'digg', 'url' => 'http://digg.com'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com'));
echo $cloud->showCloud();
?></textarea>
<!-- e: basic example -->
<br /><br />
<!-- b: basic string example -->
<h3>Basic String Example</h3>
<p>This is a basic example of how you can impliment a tag-cloud into your website by using a single string</p>
<div class="word-cloud">
<?php
$cloud = new wordCloud();
$cloud->addString('lotsofcode lotsofcode lotsofcode have developed a tag cloud that contains keywords found ');
echo $cloud->showCloud();
?>
<br /><br />
</div>
<h4>Code Example</h4>
<textarea><?php
$cloud = new wordCloud();
$cloud->addString('lotsofcode lotsofcode lotsofcode have developed a tag cloud that contains keywords found ');
echo $cloud->showCloud();
?></textarea>
<!-- e: basic string example -->
<br /><br />
<!-- b: basic example w/ links -->
<h3>Example w/ Links</h3>
<p>This is an example of how you can impliment a tag-cloud into your website including links</p>
<div class="word-cloud">
<?php
// Initite the basic object
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com'));
$myCloud = $cloud->showCloud('array');
foreach ($myCloud as $cloudArray) {
echo ' <a href="'.$cloudArray['url'].'" class="word size'.$cloudArray['range'].'">'.$cloudArray['word'].'</a> ';
}
?>
</div>
<h4>Code Example</h4>
<textarea><?php
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com'));
$myCloud = $cloud->showCloud('array');
foreach ($myCloud as $cloudArray) {
echo ' &nbsp; <a href="'.$cloudArray['url'].'" class="word size'.$cloudArray['range'].'">'.$cloudArray['word'].'</a> &nbsp;';
}
?></textarea>
<!-- e: basic example w/ links -->
<br /><br />
<!-- b: basic example w/ colours -->
<h3>Example w/ Colours</h3>
<p>This is a basic example of how you can impliment a tag-cloud into your website including colours</p>
<div class="word-cloud">
<?php
// Initite the basic object
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net', 'colour' => '#FF0000'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com', 'colour' => '#00FF00'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com', 'colour' => '#0000FF'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com', 'colour' => '#FFFF00'));
$myCloud = $cloud->showCloud('array');
foreach ($myCloud as $cloudArray) {
echo ' <span style="color: '.$cloudArray['colour'].';" class="word size'.$cloudArray['range'].'">'.$cloudArray['word'].'</span> ';
}
?>
</div>
<h4>Code Example</h4>
<textarea><?php
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net', 'colour' => '#FF0000'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com', 'colour' => '#00FF00'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com', 'colour' => '#0000FF'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com', 'colour' => '#FFFF00'));
$myCloud = $cloud->showCloud('array');
foreach ($myCloud as $cloudArray) {
echo ' &nbsp; <span style="color: '.$cloudArray['colour'].';" class="word size'.$cloudArray['range'].'">'.$cloudArray['word'].'</span> &nbsp;';
}
?></textarea>
<!-- e: basic example w/ colours -->
<br /><br />
<!-- b: basic example w/ links & colours -->
<h3>Example w/ Links & Colours</h3>
<p>This is a basic example of how you can impliment a tag-cloud into your website including links with colours</p>
<div class="word-cloud">
<?php
// Initite the basic object
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net', 'colour' => '#FF0000'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com', 'colour' => '#00FF00'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com', 'colour' => '#0000FF'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com', 'colour' => '#FFFF00'));
$myCloud = $cloud->showCloud('array');
foreach ($myCloud as $cloudArray) {
echo ' <a href="'.$cloudArray['url'].'" style="color: '.$cloudArray['colour'].';" class="word size'.$cloudArray['range'].'">'.$cloudArray['word'].'</a> ';
}
?>
</div>
<h4>Code Example</h4>
<textarea><?php
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net', 'colour' => '#FF0000'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com', 'colour' => '#00FF00'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com', 'colour' => '#0000FF'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com', 'colour' => '#FFFF00'));
$myCloud = $cloud->showCloud('array');
foreach ($myCloud as $cloudArray) {
echo ' &nbsp; <a href="'.$cloudArray['url'].'" style="color: '.$cloudArray['colour'].';" class="word size'.$cloudArray['range'].'">'.$cloudArray['word'].'</a> &nbsp;';
}
?></textarea>
<!-- e: basic example w/ links & colours -->
<br /><br />
<!-- b: basic example w/ limit -->
<h3>Example w/ Limit</h3>
<p>This is a basic example of how you can impliment a tag-cloud into your website with a limit of words</p>
<div class="word-cloud">
<?php
// Initite the basic object
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net', 'colour' => '#FF0000'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com', 'colour' => '#00FF00'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com', 'colour' => '#0000FF'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com', 'colour' => '#FFFF00'));
$cloud->setLimit(2);
echo $cloud->showCloud();
?>
</div>
<h4>Code Example</h4>
<textarea><?php
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net', 'colour' => '#FF0000'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com', 'colour' => '#00FF00'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com', 'colour' => '#0000FF'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com', 'colour' => '#FFFF00'));
$cloud->setLimit(2);
echo $cloud->showCloud();
?></textarea>
<!-- e: basic example w/ limit -->
<br /><br />
<!-- b: basic example with ordering -->
<h3>Order Results Example</h3>
<p>This is a basic example of how you can impliment a tag-cloud into your website and order the output of the results</p>
<div class="word-cloud">
<?php
// Initite the basic object
$cloud = new wordCloud();
// Basic Add Option
$cloud->addWord('php');
$cloud->addWord('google');
$cloud->addWord('digg');
$cloud->addWord('lotsofcode');
// Advanced Add Option
$cloud->orderBy('size', 'desc'); // Add Order to the cloud
echo $cloud->showCloud();
?>
<br /><br />
</div>
<h4>Code Example</h4>
<textarea><?php
$cloud = new wordCloud();
$cloud->addWord('php');
$cloud->addWord('google');
$cloud->addWord('digg');
$cloud->addWord('lotsofcode');
$cloud->orderBy('size', 'desc'); // Add Order to the cloud
echo $cloud->showCloud();
?></textarea>
<!-- e: basic example -->
<br /><br />
<!-- b: basic example w/ Ignore List -->
<h3>Example w/ Ignore List</h3>
<p>This is a basic example of how you can impliment a tag-cloud into your website with the option to ignore certain tags</p>
<div class="word-cloud">
<?php
// Initite the basic object
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net', 'colour' => '#FF0000'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com', 'colour' => '#00FF00'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com', 'colour' => '#0000FF'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com', 'colour' => '#FFFF00'));
$cloud->removeWord('digg');
$cloud->removeWord('google');
echo $cloud->showCloud();
?>
</div>
<h4>Code Example</h4>
<textarea><?php
require 'classes/wordcloud.class.php';
$cloud = new wordCloud();
$cloud->addWord(array('word' => 'php', 'size' => 1, 'url' => 'http://www.php.net', 'colour' => '#FF0000'));
$cloud->addWord(array('word' => 'google', 'size' => 2, 'url' => 'http://www.google.com', 'colour' => '#00FF00'));
$cloud->addWord(array('word' => 'digg', 'size' => 3, 'url' => 'http://digg.com', 'colour' => '#0000FF'));
$cloud->addWord(array('word' => 'lotsofcode', 'size' => 4, 'url' => 'http://www.lotsofcode.com', 'colour' => '#FFFF00'));
$cloud->removeWord('digg');
$cloud->removeWord('google');
echo $cloud->showCloud();
?></textarea>
<!-- e: basic example w/ Ignore List -->
<br /><br />
<!-- b: basic example w/ Mysql Database -->
<h3>Example w/ MySQL Database Example</h3>
<p>This is how you can include this script into a MySql result set.</p>
<textarea style="height: 300px"><?
$cloud = new wordCloud();
$getBooks = mysql_query("SELECT title FROM `tags`");
if ($getBooks)
{
while ($rowBooks = mysql_fetch_assoc($getBooks))
{
$cloud->addWord($rowBooks['title']);
}
}
$myCloud = $cloud->showCloud('array');
if (is_array($myCloud))
{
foreach ($myCloud as $key => $value)
{
echo ' <a href="./tags/'.urlencode($value['word']).'" style="font-size: 1.'.($value['range']).'em">'.$value['word'].'</a> ';
}
}
?>
</textarea>
<!-- e: basic example w/ Mysql Database -->
<br /><br />
<!-- b: basic example w/ FlatFile -->
<h3>Example w/ FlatFile</h3>
<p>This is how you can include this script into a FlatFile txt file.</p>
<textarea style="height: 300px;"><?php
require 'classes/wordcloud.class.php';
$cloud = new wordCloud();
$f = 'tags.txt'; // Filename of the text file
$s = '|'; // The char that seperates the tags
if ($h = fopen($f, 'r')) {
if (!feof($h)) {
do {
$c = fread($h, 4096);
$t = explode($s, $c);
foreach ($t as $k => $v) {
$cloud->addWord($v);
}
} while (!feof($h));
}
}
echo $cloud->showCloud();
?>
</textarea>
<!-- e: basic example w/ FlatFile -->
</form>
</div>
</body>
</html>