New modifier: slice
| From: | Ben Curtis | Date: | Thu, 14 Mar 2002 19:30:17 +0000 |
| Subject: | New modifier: slice | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-3064@lists.php.net to get a copy of this message | ||
This modifier removes the middle portion of a string -- useful for
shortening long urls. Here's the file along with some documentation
(including some sgml for you docbook junkies -- shamelessly lifted from
the truncate section of the doc).
Attachment: [application/x-httpd-php] modifier.slice.php
Attachment: [text/html] slice.html
<!DOCTYPE sect3 PUBLIC "-//OASIS//DTD DocBook V3.1//EN"> <sect3> <title>slice</title> <informaltable frame=all> <tgroup cols=3> <colspec colname=param> <colspec colname=type> <colspec colname=required> <colspec colname=default> <colspec colname=desc> <thead> <row> <entry>Parameter Position</entry> <entry>Type</entry> <entry>Required</entry> <entry>Default</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>1</entry> <entry>integer</entry> <entry>No</entry> <entry>80</entry> <entry>This determines the length of the resultant string.</entry> </row> <row> <entry>2</entry> <entry>string</entry> <entry>No</entry> <entry>...</entry> <entry>This is the text to replace the middle portion of the string.</entry> </row> <row> <entry>3</entry> <entry>boolean</entry> <entry>No</entry> <entry>true</entry> <entry>This determines whether or not to truncate at a word boundary (false), or at the exact character (true).</entry> </row> </tbody> </tgroup> </informaltable> <para> This replaces the middle of a variable to achieve a string with a specific character length, default is 80. As an optional second parameter, you can specify a string of text that will replace the deleted segment. The characters in the string are included with the original truncation length. By default, slice will ignore word boundaries. If you want to split at a space, pass the optional third parameter of false. </para> <example> <title>slice</title> <programlisting> {$url} {$url|slice} {$url|slice:20} {$url|slice:20:""} {$url|slice:20:"---"} OUTPUT: http://www.phpinsider.com/ http://www.phpinsider.com/ http://ww...der.com/ http://wwwider.com/ http://ww---der.com/</programlisting> </example> </sect3>
Attachment: [application/x-httpd-php] modifier.slice.php
Attachment: [text/html] slice.html
<!DOCTYPE sect3 PUBLIC "-//OASIS//DTD DocBook V3.1//EN"> <sect3> <title>slice</title> <informaltable frame=all> <tgroup cols=3> <colspec colname=param> <colspec colname=type> <colspec colname=required> <colspec colname=default> <colspec colname=desc> <thead> <row> <entry>Parameter Position</entry> <entry>Type</entry> <entry>Required</entry> <entry>Default</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>1</entry> <entry>integer</entry> <entry>No</entry> <entry>80</entry> <entry>This determines the length of the resultant string.</entry> </row> <row> <entry>2</entry> <entry>string</entry> <entry>No</entry> <entry>...</entry> <entry>This is the text to replace the middle portion of the string.</entry> </row> <row> <entry>3</entry> <entry>boolean</entry> <entry>No</entry> <entry>true</entry> <entry>This determines whether or not to truncate at a word boundary (false), or at the exact character (true).</entry> </row> </tbody> </tgroup> </informaltable> <para> This replaces the middle of a variable to achieve a string with a specific character length, default is 80. As an optional second parameter, you can specify a string of text that will replace the deleted segment. The characters in the string are included with the original truncation length. By default, slice will ignore word boundaries. If you want to split at a space, pass the optional third parameter of false. </para> <example> <title>slice</title> <programlisting> {$url} {$url|slice} {$url|slice:20} {$url|slice:20:""} {$url|slice:20:"---"} OUTPUT: http://www.phpinsider.com/ http://www.phpinsider.com/ http://ww...der.com/ http://wwwider.com/ http://ww---der.com/</programlisting> </example> </sect3>