Forum : How to solve the below query?
Brief description  about Online courses   join in Online courses
View Sweety  Agarwal 's Profile

How to solve the below query?

Write a program which takes name of user as a input in text box and truncate the name if it is more than 10 characters using truncate modifiers..

truncate.php

<?php
require 'smarty/libs/Smarty.class.php';
$smarty =new smarty();


$smarty->display('truncate.tpl');

?>

truncate.tpl

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="nirmal" />

<title>Untitled 4</title>
</head>

<body>

<form action="receive.php" method="post">
Name: <input type="text" name="name" />
</form>
{$a|truncate:10}
</body>
</html>


receive.php

<?php
require 'smarty/libs/Smarty.class.php';
$smarty =new smarty();

$b=$_POST["name"];
$smarty->assign('a','$b');

?>
Asked by Sweety Agarwal | Dec 30, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
catch name value in any variable like $a=$_POST['name'];
assign that variable to a smarty variable use of smarty assign method $smarty->assign('a',$a);
$smarty->display("abc.tpl") ;

and catch a variable on smarty page and use truncate modifire
{$a|truncate:10}
it will work
before it you have to give a proper path.
Jan 3, 2011