小编Kes*_*air的帖子

如何制作一个php模板引擎?

我需要制作一个小而简单的php模板引擎,我搜索了很多,其中很多都太复杂,无法理解,我不想使用smarty和其他类似的引擎,我从Stack Overflow有一些想法,如下所示:

$template = file_get_contents('file.html');
$array = array('var1' => 'value',
                'txt' => 'text');

foreach($array as $key => $value)
{
  $template = str_replace('{'.$key.'}', $value, $template);
}

echo $template;
Run Code Online (Sandbox Code Playgroud)

现在,而不是回显模板我只想添加包含"file.html",它将显示具有正确变量值的文件,我想将引擎放在一个单独的位置,只是将它包含在模板中我要使用的内容它声明了数组,最后包含像phpbb这样的html文件.对不起,我要求的很多,但任何人都可以解释一下这背后的基本概念吗?

编辑:嗯,让我坦率地说我正在制作一个论坛脚本,我有很多想法,但我想让它的模板系统像phpbb所以我需要一个单独的模板引擎自定义如果你可以帮助那么请你被邀请和我一起工作 抱歉广告..:p

html php arrays templates

6
推荐指数
2
解决办法
1万
查看次数

PostgreSQL UPDATE相当于MySQL查询

我有一个简单的MySQL查询,我想转换为PostgreSQL.3天后我终于退出了,因为我不明白这里有什么不妥:

UPDATE webUsers u, 
(SELECT IFNULL(count(s.id),0) AS id, p.associatedUserId FROM pool_worker p 
LEFT JOIN shares s ON p.username=s.username 
WHERE s.our_result='Y' GROUP BY p.associatedUserId) a
SET shares_this_round = a.id WHERE u.id = a.associatedUserId
Run Code Online (Sandbox Code Playgroud)

我试图转换它,但它说SET上的错误.这是我的查询:

UPDATE webusers 
SET (shares_this_round) = (a.id)
FROM (SELECT coalesce(count(s.id),0) AS id, p.associatedUserId FROM pool_worker p 
LEFT JOIN shares s ON p.username=s.username WHERE s.our_result='Y' GROUP BY p.associatedUserId) a, webusers w WHERE u.id = a.associatedUserId
Run Code Online (Sandbox Code Playgroud)

谁能告诉我它有什么问题?因为这个原因,我无法入睡.

     ------------------------------EDIT-------------------------------------
Run Code Online (Sandbox Code Playgroud)

股份表

CREATE TABLE shares (
id bigint NOT NULL,
rem_host character varying(255) …
Run Code Online (Sandbox Code Playgroud)

mysql sql postgresql sql-update

3
推荐指数
1
解决办法
693
查看次数

php mysql AND运算符

我收到一条错误消息:

您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在第1行'key ='12345'和id ='98765'LIMIT 1'附近使用正确的语法

我的代码是:

$key = '12345'; 
$id = '98765';  
include realpath('./inc/config.php');

            $query = mysql_query("SELECT * FROM users WHERE key='{$key}' AND id='{$id}' LIMIT 1", $config) or die(mysql_error());
            $result = mysql_fetch_assoc($query);
Run Code Online (Sandbox Code Playgroud)

现在有谁能告诉我这有什么不对吗?

php mysql mysql-error-1064

1
推荐指数
1
解决办法
2076
查看次数

c libev undefined对`ev_default_loop'的引用

我在ubuntu上运行gcc编译器我正在使用一个例子来学习如何与libev建立套接字连接我已经安装了libev4和libev-dev但是一切正常,除非我添加struct ev_loop*loop = ev_default_loop(0); 它抛出一个未定义的引用错误任何人都可以告诉我这里有什么问题是我的代码

#include <stdio.h>
#include <netinet/in.h>
#include <ev.h>

#define PORT_NO 3033
#define BUFFER_SIZE 1024

int total_clients = 0;  // Total number of connected clients

void accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents);
void read_cb(struct ev_loop *loop, struct ev_io *watcher, int revents);

int main() {
    struct ev_loop *loop = ev_default_loop(0); <--error-->
    int sd;
    struct sockaddr_in addr;
    int addr_len = sizeof(addr);
    struct ev_io w_accept;

    // Create server socket
    if ((sd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
        perror("socket …
Run Code Online (Sandbox Code Playgroud)

c libev

1
推荐指数
1
解决办法
3177
查看次数

如何在php的同一页面中将变量从一个函数传递到另一个函数?

好了,我现在有另一个问题,我想将一个或多个变量从一个函数发送到另一个函数,如下所示:

class test{

    var $text2;

    function text1($text1){ // This will catch "This is text" from $text variable.

        $text1 = $this -> text2; // Giving $text1 value to $text2 

        return $this -> text2; // Now here is the trouble i think, i want to send the variable to the next function that is text2(). How do i do that?

    }
    function text2($text2){ // Here is the place that says undefined variable i want the variable $text2 from function text1() to be …
Run Code Online (Sandbox Code Playgroud)

php variables class function

-1
推荐指数
1
解决办法
7549
查看次数