This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi.pitch_firstword.php
70 lines (56 loc) · 1.76 KB
/
pi.pitch_firstword.php
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
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* ExpressionEngine - by EllisLab
*
* @package ExpressionEngine
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2003 - 2011, EllisLab, Inc.
* @license http://expressionengine.com/user_guide/license.html
* @link http://expressionengine.com
* @since Version 2.0
*/
/**
* Pitch First Word Plugin
*
* @package ExpressionEngine
* @subpackage Addons
* @category Plugin
* @author Pitch
* @link http://pitch.net.nz
*/
$plugin_info = array(
'pi_name' => 'Pitch First Word',
'pi_version' => '1.0.0',
'pi_author' => 'Pitch',
'pi_author_url' => 'http://pitch.net.nz',
'pi_description'=> 'A plugin to show only the first word of a string.',
'pi_usage' => Pitch_firstword::usage()
);
class Pitch_firstword
{
function pitch_firstword()
{
// First lets get an instance of EE.
$this->EE =&get_instance();
// Grab the contents of our plugin tag
$full_string = $this->EE->TMPL->tagdata;
// Now just grab the first word from the string and put in an array
$full_string = explode(' ', $full_string);
// Return that word for usage by grabbing the first item of the array if there isn't a name die quietly
$this->return_data = (isset($full_string[0])) ? $full_string[0] : '';
}
function usage()
{
ob_start();
?>
Use this when you need to output ony the first word of a string some examples are below.
{exp:pitch_firstword}Ben Lilley{/exp:pitch_firstword} would output "Ben"
{exp:pitch_firstword}{person-fullname}{/exp:pitch_firstword}
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
}
/* End of file pi.pitch_firstword.php */
/* Location: /system/expressionengine/third_party/pitch_firstword/pi.pitch_firstword.php */