|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
mozolici Smarty Rookie
Joined: 18 Aug 2007 Posts: 21 Location: Suceava / Romania
|
Posted: Tue May 26, 2009 1:02 pm Post subject: if with stristr case |
|
|
how to modify this code in tpl format?
Code: | <?php
$string = 'Hello World!';
if(stristr($string, 'earth') === FALSE) {
echo '"earth" not found in string';
}
// outputs: "earth" not found in string
?> |
i try to use this but dosent work
Code: | {if (stristr($string, 'earth') === FALSE)}
"earth" not found in string'
{/if} |
_________________ be fiRst but fiRst think fiRst! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue May 26, 2009 1:11 pm Post subject: |
|
|
Try this:
Code: | {if $string|stristr:"earth"}
earth found
{else}
earth not found
{/if} |
|
|
Back to top |
|
mozolici Smarty Rookie
Joined: 18 Aug 2007 Posts: 21 Location: Suceava / Romania
|
Posted: Tue May 26, 2009 6:10 pm Post subject: |
|
|
thanks for first code
i need some .... more help
i have this php code
Code: | $categ = array(10=>"apple",245=>"microsoft",3=>"samsung",22=>"hp");
//and
$query = 'SELECT * FROM categ;
$result = mysql_query ($query) or die ('Query Faild: '. mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$count++;
$categ[] = $line;
$item = explode(":", $line['item']);
} |
in tpl i need to convert explode code and make some moves
becouse in db i have 10:22 ori 10:3
if i try in tpl
-------------------------
Code: | {$line.item|explode:":":""} |
i receive in html
if i try in tpl
-----------------------
//becouse in db i have 10:3
Code: | {$categ[$line.item|explode:":":""]} // to create array {$categ[10]} that represent apple and {$categ[3]} that represent samsung |
i receive error
Code: | Warning: explode() [function.explode]: Empty delimiter in ...line 22 |
where do you think that i am wrong? _________________ be fiRst but fiRst think fiRst!
Last edited by mozolici on Tue May 26, 2009 6:14 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue May 26, 2009 6:13 pm Post subject: |
|
|
explode in PHP, then assign to the template? |
|
Back to top |
|
mozolici Smarty Rookie
Joined: 18 Aug 2007 Posts: 21 Location: Suceava / Romania
|
Posted: Tue May 26, 2009 7:40 pm Post subject: |
|
|
i create 2 arrays in php with explode
this code in tpl works
----------------
Code: | //first array
{$arrayFirst[$line.id][0]} --- output // 10
{$arrayFirst[$line.id][1]} --- output // 3
//second array
{$arraySecond[10]} --- output // apple
{$arraySecond[3]} --- output // samsung |
i want to make a combination with 2 arrays to create a dynamic site and i want to modify second array
this code
------------------
Code: | {$arraySecond[10]} // instead 10 to put {$arrayFirst[$line.id][0]} |
something like this ... but dosent work
Code: | {$arraySecond[$arrayFirst[$line.id][0]}]}//to make dinamically |
any solution _________________ be fiRst but fiRst think fiRst! |
|
Back to top |
|
mozolici Smarty Rookie
Joined: 18 Aug 2007 Posts: 21 Location: Suceava / Romania
|
Posted: Tue May 26, 2009 8:41 pm Post subject: |
|
|
i used assign var="foo"
and works
topic closed _________________ be fiRst but fiRst think fiRst! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|