【发布时间】:2013-02-04 04:44:29
【问题描述】:
下面这个 PHP 代码在 Smarty 中的调用将不起作用
PHP 中的示例用法
$content=@file_get_contents("http://www.gempixel.com/short/api/?url=http://www.google.com&api=APIKEY");
$url=json_decode($content,TRUE);//Decodes json into an array
if(!$url["error"]){ // If there is no error
echo $url["short"]; //Outputs the short url
}else{
echo $url["msg"]; //Outputs the error message
}
对于 Smarty,我只需要将 php 替换为 {php} 即可。
{php}$shortenedurl = file_get_contents('http://www.gempixel.com/short/api/?api=fAaFjILdbigF&url=' . urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));{/php}
{php}$url=json_decode($content,TRUE);if(!$url["error"]){echo $url["short"];}else{echo $url["msg"];}{/php}
但它不会调用字符串。我做错了什么?
【问题讨论】:
-
我认为模板的全部目的是将代码与设计分开......
-
@OneTrickPony,朋友,谢谢你睁开眼睛;)