0

我正在编写一个 channel.htm 形式的代码并存储在 sd 存储卡中。但是当我运行 channel.htm 页面时。它向我展示了 php 代码。我不知道该怎么办。有人可以帮忙吗?我正在对在 sd 卡上运行的 arduino 进行实验。

帮助

  <!DOCTYPE html>
    <html>
        <head>
            <title>Arduino SD card Web Page</title>
        </head>
        <body>
            <h1> Hello I am testing Arduino SD card connected to web page</h1>
            <p> A web page from SD card server. </p>

    <?php

    $a1=array( "channelOne"=>"-45",
    "channelTwo"=>"-100",
    "channelThree"=>"-20"  );

    $a2=array(
    "channelOne"=>"-48",
    "channelTwo"=>"-90",
    "channelThree"=>"-22"
    );

    $diff = array_map(
        function ($a1, $a2)
        {
            return abs($a1-$a2);
        }, $a1,$a2
    );
    print_r($diff);

    array_walk($a1,
    function ($v, $k) use ($a1,$a2)
    {
        $v = abs($a1[$k]-$a2[$k]);
    });
    print_r($a1);
    print_r($a2);

    ob_start();
    echo"<br>";echo"<br><pre>";print_r($diff);echo"</pre>";

    $content = ob_get_contents();

    $f = fopen("file.html", "w");
    fwrite($f, $content);
    fclose($f); 

    echo "<input type='submit' value='Write'>"



    ?> 

        </body>

    </html>

这是结果 "-45", "channelTwo"=>"-100", "channelThree"=>"-20" ); $a2=array("channelOne"=>"-48", "channelTwo"=>"-90", "channelThree"=>"-22"); $diff = array_map( function ($a1, $a2) { return abs($a1-$a2); }, $a1,$a2 ); print_r($diff); array_walk($a1, 函数 ($v, $k) 使用 ($a1,$a2) { $v = abs($a1[$k]-$a2[$k]); }); print_r($a1); print_r($a2); ob_start(); 回声" ";回声"

";print_r($diff);echo"

"; $content = ob_get_contents(); $f = fopen("file.html", "w"); fwrite($f, $content); fclose($f); echo "" /*$result=print_r( $diff); $ourFileHandle = fopen("name.txt", 'w') ; fwrite($ourFileHandle,"diff"); fclose($ourFileHandle); echo "Written";*/ /*foreach($a1 as $Name=>$Temperature) { echo "Channel_Name"." “.$名字。” “。”Actual_Temperature“。” “.$温度。” "; } foreach($a2 as $Name=>$Temperature_Now) { echo "Channel_Name"." “.$名字。” "."Temperature_Now"." “.$Temperature_Now。” "; }*/ ?>

4

2 回答 2

2

您应该将您的channel.htm(如果它是您拥有的唯一文件)或您获得的整个页面文件夹复制到 wamp 服务器的 www 文件夹,如果是 xampp 服务器,则复制其 htdocs 文件夹。localhost/channel.htm在第一种情况下或localhost/<address to your page starting from www or htdocs folder>在您的 Web 浏览器中运行 Web 服务和 goto 。这是您可以运行包含 php 代码的网页的方式。但是请阅读更多关于服务器端与客户端语言以及 php 如何在后面工作的内容。快乐编码:-)

于 2013-10-14T17:35:33.287 回答
0

Firstly, you need to ensure that you actually have php installed on your Arduino device. I'm sure a quick Google around will find someone who has created various bits of software to do this. Try searching for 'Arduino LAMP Server'.

Secondly, unless you've set it up very strangely, files that end in .html, or .htm will not parse PHP code. The standard setup for all major web servers doesn't process a server-side language like PHP in HTML files, and mostly, PHP files end in '.php' (Some end in .php3, .php4, .php5 etc to indicate PHP version - but this is fairly rare actually).

It'll take some fiddling to get an arduino running a server and php process, but it may be doable, good luck.

于 2013-10-14T17:05:18.493 回答