JSON输出文件中数组元素之间的新行

时间:2015-08-02 16:18:26

标签: php arrays json

我试图找到一种在数组元素之间添加新行的方法。我有一个超过JSON数据的php文件,因为我有这一行 - <p>由于这些数据总是打印在一行,<br>\n$vs['title']是被视为文本而不是代码。 while只是从查询中运行数据,该查询将值插入$vs['description']Title - my title Value - my value

如何让它像这样打印:

 Title - my title Value - my value    

而不是:

$vs1=array();
    while($res2 = oci_fetch_array($result2))  {
     $vs=array();
     $vs['title']='Title'.$res2['CATEGORIA_DESC'];
     $vs['description']= 'Value - '.$res2['VALOR'];

 array_push($vs1,$vs);
}

echo str_replace(array('[', ']'), '', htmlspecialchars(json_encode($vs1), ENT_NOQUOTES));

PHP文件的一部分

#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdbool.h>
#include <string.h>
#include "tpl.h"

//This example contains two different parts:
        //1) The alarm is a execution timer for the function doWork
        //2) There is a need, that if the execution exits correctly, that the chid value of i, that we are modifying be passes

typedef struct TEST_STRUCT
{
        int i;
        double sum;
} testStruct;

int doWork(testStruct * ts)
{
        int y;
        for(y=0; y<3; y++)
        {
                sleep(1);
                printf("Working: %d\n", ts->i);
                ts->i++;
                ts->sum += (double)ts->i;
        }
        return 0;
}
int main()
{

        testStruct * ts = (testStruct *)(calloc(1, sizeof(testStruct)));
        ts->i = 7;
        ts->sum = 4.0;

        tpl_node *tn;
        int fd[2];
        pipe(fd);
        int y;
        for(y=0; y<10; y++)
        {
                pid_t childPID = fork();
                if (childPID==0)
                {
                        unsigned secsLeft;
                        alarm(10);
                        doWork(ts);

                        printf("\t->%d\n", ts->i);
                        printf("\t->%p\n", (void*) &ts->i);

                        tn = tpl_map("S(if)", ts);
                        tpl_pack( tn, 0 );
                        tpl_dump( tn, TPL_FD, fd[1]);
                        tpl_free( tn );

                        secsLeft = alarm(0);
                        exit(0);
                }
                else
                {
                        //IMPORTANT TO PUT IT HERE: In case the buffer is too big, TPL_DUMP will wait until it can send another and hang
                        tn = tpl_map( "S(if)", ts );
                        tpl_load( tn, TPL_FD, fd[0]);

                        int status;
                        wait(&status);

                        if(WIFSIGNALED(status))
                        {
                                // child was interrupted
                                if (WTERMSIG(status) == SIGALRM)
                                {
                                        printf("Interrupted\n");
                                        // child interrupted by alarm signal
                                }
                                else
                                {
                                        printf("Should not happend\n");
                                         // child interrupted by another signal
                                }
                        }
                        else
                        {
                                tpl_unpack(tn,0);
                                tpl_free( tn );

                                printf("\t->%d\n", ts->i);
                                printf("\t->%p\n", (void*) &ts->i);
                                printf("Success\n");
                        }
                }
        }
        return 0;
}

1 个答案:

答案 0 :(得分:0)

如果您只想显示数据,可以在while循环中执行:

while ($res2 = oci_fetch_array($result2))  {
    echo "<hr/>";
    echo "<div>Title {$res2['CATEGORIA_DESC']}</div>";
    echo "<div>Value - {$res2['VALOR']}</div>";
}