mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
finished this file :)
This commit is contained in:
@@ -752,8 +752,8 @@ href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">bob
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('articleTitle', 'NJ judge to rule on nude beach.');
|
$smarty->assign('articleTitle', 'NJ judge to rule on nude beach.');
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
]]>
|
]]>
|
||||||
@@ -913,26 +913,38 @@ Sun or rain expected<br />today, dark tonight
|
|||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>regex_replace</title>
|
<title>regex_replace</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('articleTitle', "Infertility unlikely to\nbe passed on, experts say.");
|
$smarty->assign('articleTitle', "Infertility unlikely to\nbe passed on, experts say.");
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
index.tpl:
|
?>
|
||||||
|
]]>
|
||||||
{* replace each carriage return, tab & new line with a space *}
|
|
||||||
|
|
||||||
{$articleTitle}
|
|
||||||
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
Infertility unlikely to
|
|
||||||
be passed on, experts say.
|
|
||||||
Infertility unlikely to be passed on, experts say.
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
Where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{* replace each carriage return, tab and new line with a space *}
|
||||||
|
|
||||||
|
{$articleTitle}
|
||||||
|
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This should output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
Infertility unlikely to
|
||||||
|
be passed on, experts say.
|
||||||
|
Infertility unlikely to be passed on, experts say.
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.replace">
|
<sect1 id="language.modifier.replace">
|
||||||
@@ -976,25 +988,37 @@ Sun or rain expected<br />today, dark tonight
|
|||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>replace</title>
|
<title>replace</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
|
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
index.tpl:
|
?>
|
||||||
|
]]>
|
||||||
{$articleTitle}
|
|
||||||
{$articleTitle|replace:"Garden":"Vineyard"}
|
|
||||||
{$articleTitle|replace:" ":" "}
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
Child's Stool Great for Use in Garden.
|
|
||||||
Child's Stool Great for Use in Vineyard.
|
|
||||||
Child's Stool Great for Use in Garden.
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
Where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{$articleTitle}
|
||||||
|
{$articleTitle|replace:"Garden":"Vineyard"}
|
||||||
|
{$articleTitle|replace:" ":" "}
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This should output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
Child's Stool Great for Use in Garden.
|
||||||
|
Child's Stool Great for Use in Vineyard.
|
||||||
|
Child's Stool Great for Use in Garden.
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.spacify">
|
<sect1 id="language.modifier.spacify">
|
||||||
@@ -1033,25 +1057,35 @@ Sun or rain expected<br />today, dark tonight
|
|||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>spacify</title>
|
<title>spacify</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
|
$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
?>
|
||||||
index.tpl:
|
]]>
|
||||||
|
|
||||||
{$articleTitle}
|
|
||||||
{$articleTitle|spacify}
|
|
||||||
{$articleTitle|spacify:"^^"}
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
Something Went Wrong in Jet Crash, Experts Say.
|
|
||||||
S o m e t h i n g W e n t W r o n g i n J e t C r a s h , E x p e r t s S a y .
|
|
||||||
S^^o^^m^^e^^t^^h^^i^^n^^g^^ ^^W^^e^^n^^t^^ ^^W^^r^^o^^n^^g^^ ^^i^^n^^ ^^J^^e^^t^^ ^^C^^r^^a^^s^^h^^,^^ ^^E^^x^^p^^e^^r^^t^^s^^ ^^S^^a^^y^^.
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
Where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{$articleTitle}
|
||||||
|
{$articleTitle|spacify}
|
||||||
|
{$articleTitle|spacify:"^^"}
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This should output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
Something Went Wrong in Jet Crash, Experts Say.
|
||||||
|
S o m e t h i n g W e n t W r o n g i n J e t C r a s h , E x p e r t s S a y .
|
||||||
|
S^^o^^m^^e^^t^^h^^i^^n^^g^^ ^^W^^e^^n^^t^^ ^^W^^r^^o^^n^^g^^ ^^i^^n^^ ^^J^^e^^t^^ ^^C^^r^^a^^s^^h^^,^^ ^^E^^x^^p^^e^^r^^t^^s^^ ^^S^^a^^y^^.
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.string.format">
|
<sect1 id="language.modifier.string.format">
|
||||||
@@ -1089,25 +1123,37 @@ Sun or rain expected<br />today, dark tonight
|
|||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>string_format</title>
|
<title>string_format</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('number', 23.5787446);
|
$smarty->assign('number', 23.5787446);
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
index.tpl:
|
?>
|
||||||
|
]]>
|
||||||
{$number}
|
|
||||||
{$number|string_format:"%.2f"}
|
|
||||||
{$number|string_format:"%d"}
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
23.5787446
|
|
||||||
23.58
|
|
||||||
24
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
Where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{$number}
|
||||||
|
{$number|string_format:"%.2f"}
|
||||||
|
{$number|string_format:"%d"}
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This should output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
23.5787446
|
||||||
|
23.58
|
||||||
|
24
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.strip">
|
<sect1 id="language.modifier.strip">
|
||||||
@@ -1125,28 +1171,38 @@ Sun or rain expected<br />today, dark tonight
|
|||||||
</note>
|
</note>
|
||||||
<example>
|
<example>
|
||||||
<title>strip</title>
|
<title>strip</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
index.php:
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('articleTitle', "Grandmother of\neight makes\t hole in one.");
|
$smarty->assign('articleTitle', "Grandmother of\neight makes\t hole in one.");
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
index.tpl:
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|strip}
|
{$articleTitle|strip}
|
||||||
{$articleTitle|strip:" "}
|
{$articleTitle|strip:" "}
|
||||||
|
]]>
|
||||||
OUTPUT:
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This will output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
Grandmother of
|
Grandmother of
|
||||||
eight makes hole in one.
|
eight makes hole in one.
|
||||||
Grandmother of eight makes hole in one.
|
Grandmother of eight makes hole in one.
|
||||||
Grandmother of eight makes hole in one.
|
Grandmother of eight makes hole in one.
|
||||||
]]>
|
]]>
|
||||||
</programlisting>
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.strip.tags">
|
<sect1 id="language.modifier.strip.tags">
|
||||||
@@ -1156,23 +1212,36 @@ Grandmother of eight makes hole in one.
|
|||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>strip_tags</title>
|
<title>strip_tags</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('articleTitle', "Blind Woman Gets <font face=\"helvetica\">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.");
|
$smarty->assign('articleTitle', "Blind Woman Gets <font face=\"helvetica\">New
|
||||||
$smarty->display('index.tpl');
|
Kidney</font> from Dad she Hasn't Seen in <b>years</b>.");
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
index.tpl:
|
?>
|
||||||
|
]]>
|
||||||
{$articleTitle}
|
|
||||||
{$articleTitle|strip_tags}
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
Blind Woman Gets <font face="helvetica">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.
|
|
||||||
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{$articleTitle}
|
||||||
|
{$articleTitle|strip_tags}
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This will output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
Blind Woman Gets <font face="helvetica">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.
|
||||||
|
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.truncate">
|
<sect1 id="language.modifier.truncate">
|
||||||
@@ -1231,33 +1300,45 @@ Grandmother of eight makes hole in one.
|
|||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>truncate</title>
|
<title>truncate</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
|
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
index.tpl:
|
?>
|
||||||
|
]]>
|
||||||
{$articleTitle}
|
|
||||||
{$articleTitle|truncate}
|
|
||||||
{$articleTitle|truncate:30}
|
|
||||||
{$articleTitle|truncate:30:""}
|
|
||||||
{$articleTitle|truncate:30:"---"}
|
|
||||||
{$articleTitle|truncate:30:"":true}
|
|
||||||
{$articleTitle|truncate:30:"...":true}
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
|
||||||
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
|
||||||
Two Sisters Reunite after...
|
|
||||||
Two Sisters Reunite after
|
|
||||||
Two Sisters Reunite after---
|
|
||||||
Two Sisters Reunite after Eigh
|
|
||||||
Two Sisters Reunite after E...
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{$articleTitle}
|
||||||
|
{$articleTitle|truncate}
|
||||||
|
{$articleTitle|truncate:30}
|
||||||
|
{$articleTitle|truncate:30:""}
|
||||||
|
{$articleTitle|truncate:30:"---"}
|
||||||
|
{$articleTitle|truncate:30:"":true}
|
||||||
|
{$articleTitle|truncate:30:"...":true}
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This will output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
||||||
|
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
||||||
|
Two Sisters Reunite after...
|
||||||
|
Two Sisters Reunite after
|
||||||
|
Two Sisters Reunite after---
|
||||||
|
Two Sisters Reunite after Eigh
|
||||||
|
Two Sisters Reunite after E...
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.upper">
|
<sect1 id="language.modifier.upper">
|
||||||
@@ -1267,23 +1348,35 @@ Grandmother of eight makes hole in one.
|
|||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>upper</title>
|
<title>upper</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('articleTitle', "If Strike isn't Settled Quickly it may Last a While.");
|
$smarty->assign('articleTitle', "If Strike isn't Settled Quickly it may Last a While.");
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
index.tpl:
|
?>
|
||||||
|
]]>
|
||||||
{$articleTitle}
|
|
||||||
{$articleTitle|upper}
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
If Strike isn't Settled Quickly it may Last a While.
|
|
||||||
IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE.
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{$articleTitle}
|
||||||
|
{$articleTitle|upper}
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This will output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
If Strike isn't Settled Quickly it may Last a While.
|
||||||
|
IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE.
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.wordwrap">
|
<sect1 id="language.modifier.wordwrap">
|
||||||
@@ -1341,45 +1434,57 @@ Grandmother of eight makes hole in one.
|
|||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>wordwrap</title>
|
<title>wordwrap</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('articleTitle', "Blind woman gets new kidney from dad she hasn't seen in years.");
|
$smarty->assign('articleTitle', "Blind woman gets new kidney from dad she hasn't seen in years.");
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
index.tpl:
|
?>
|
||||||
|
]]>
|
||||||
{$articleTitle}
|
|
||||||
|
|
||||||
{$articleTitle|wordwrap:30}
|
|
||||||
|
|
||||||
{$articleTitle|wordwrap:20}
|
|
||||||
|
|
||||||
{$articleTitle|wordwrap:30:"<br>\n"}
|
|
||||||
|
|
||||||
{$articleTitle|wordwrap:30:"\n":true}
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
Blind woman gets new kidney from dad she hasn't seen in years.
|
|
||||||
|
|
||||||
Blind woman gets new kidney
|
|
||||||
from dad she hasn't seen in
|
|
||||||
years.
|
|
||||||
|
|
||||||
Blind woman gets new
|
|
||||||
kidney from dad she
|
|
||||||
hasn't seen in
|
|
||||||
years.
|
|
||||||
|
|
||||||
Blind woman gets new kidney<br>
|
|
||||||
from dad she hasn't seen in years.
|
|
||||||
|
|
||||||
Blind woman gets new kidney fr
|
|
||||||
om dad she hasn't seen in year
|
|
||||||
s.
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{$articleTitle}
|
||||||
|
|
||||||
|
{$articleTitle|wordwrap:30}
|
||||||
|
|
||||||
|
{$articleTitle|wordwrap:20}
|
||||||
|
|
||||||
|
{$articleTitle|wordwrap:30:"<br>\n"}
|
||||||
|
|
||||||
|
{$articleTitle|wordwrap:30:"\n":true}
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This will output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
Blind woman gets new kidney from dad she hasn't seen in years.
|
||||||
|
|
||||||
|
Blind woman gets new kidney
|
||||||
|
from dad she hasn't seen in
|
||||||
|
years.
|
||||||
|
|
||||||
|
Blind woman gets new
|
||||||
|
kidney from dad she
|
||||||
|
hasn't seen in
|
||||||
|
years.
|
||||||
|
|
||||||
|
Blind woman gets new kidney<br>
|
||||||
|
from dad she hasn't seen in years.
|
||||||
|
|
||||||
|
Blind woman gets new kidney fr
|
||||||
|
om dad she hasn't seen in year
|
||||||
|
s.
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user