使用者:游士賢:修訂版本之間的差異
出自福留子孫
(→php呼叫python顯示於網頁) |
|||
| (未顯示2位用戶所作出之22次版本) | |||
| 第 1 行: | 第 1 行: | ||
| − | == | + | <details><summary>2025 後</summary> |
| + | # 每週約來一次<br/>----------向遠哲佩君請款---------- | ||
| + | # <s>[http://jendo.org/uploadFiles/s4e/第三期申請補助/ 第三期申請補助資料櫃] | ||
| + | # [http://jendo.org/uploadFiles/s4e/第三期申請補助/動手學科學領據-空白(4800).doc 領據樣張] | ||
| + | # [http://jendo.org/uploadFiles/s4e/第三期申請補助/個人所得領據.doc 空白領據] | ||
| + | # [http://quality-learning.net/adminer-5.4.1-mysql.php?server=db-57.coowo.com%3A3306&username=adminwiki&db=wiki&select=2024Person&columns%5B0%5D%5Bfun%5D=&columns%5B0%5D%5Bcol%5D=&where%5B0%5D%5Bcol%5D=nameZh&where%5B0%5D%5Bop%5D=%3D&where%5B0%5D%5Bval%5D=李國章 李國章的基本資料] | ||
| + | # [http://jendo.org/uploadFiles/s4e/第三期申請補助/核結請款/readme.htm readme.htm]<br/></s>----------列車---------- | ||
| + | # 維護手冊 | ||
| + | # 維護簡報 | ||
| + | # 場次維護介面 / keyman 資料 | ||
| + | # <s>維護嘉義場次參與者資料</s><br/>----------台灣全社會靭性兩論壇----------<br/>----------辦公室基礎業務---------- | ||
| + | # <s>繳費 | ||
| + | #*伙伴勞健保: | ||
| + | #*電話 / 頻寬:中華電信 | ||
| + | #*水電:自強國中總務處 | ||
| + | #*房租:自強國中總務處</s> | ||
| + | # <s>維護「DS218 / video / 匯款」</s> | ||
| + | # <s>剪報</s> | ||
| + | # <s>從黃鈴諭兒子處取回工作帳號</s> | ||
| + | # 網約短約工作平台 | ||
| + | # [[Etherpad#五、資料修復|救 Etherpad]] | ||
| + | </details> | ||
| + | ==php+python顯示於網頁== | ||
===範例一、文字顯示=== | ===範例一、文字顯示=== | ||
| − | *說明:利用 php 讀取 python | + | *說明:利用 php 讀取 python 檔案,並將文字顯示「Hello, world!」於頁面上。 |
| − | *範例程式:[http://jendo.org/~游士賢/chatgcp/ | + | *範例程式:[http://jendo.org/~游士賢/chatgcp/02 連結] |
| − | ''' | + | '''index.php,程式碼如下:''' |
<pre> | <pre> | ||
| 第 25 行: | 第 47 行: | ||
'''word.py,程式碼如下:''' | '''word.py,程式碼如下:''' | ||
<pre> | <pre> | ||
| − | print("Hello, | + | print("Hello, world!") |
</pre> | </pre> | ||
===範例二、兩數相加算術=== | ===範例二、兩數相加算術=== | ||
*說明:利用 php 讀取 python 檔案,並使用者將兩個數值填入並按計算,答案將顯示於網頁上。 | *說明:利用 php 讀取 python 檔案,並使用者將兩個數值填入並按計算,答案將顯示於網頁上。 | ||
| − | *範例程式:[http://jendo.org/~游士賢/chatgcp/ | + | *範例程式:[http://jendo.org/~游士賢/chatgcp/03 連結] |
'''index.php,程式碼如下:''' | '''index.php,程式碼如下:''' | ||
| 第 82 行: | 第 104 行: | ||
# 將結果返回給 PHP | # 將結果返回給 PHP | ||
print(result) | print(result) | ||
| + | </pre> | ||
| + | |||
| + | ==php+xml顯示於網頁== | ||
| + | ===範例一、已知兩數,應用php讀取xml數值=== | ||
| + | *說明:xml 檔案已存在兩位數「12」和「34」,應用php讀取xml檔,將答案將顯示於網頁上。 | ||
| + | *範例程式:[http://jendo.org/~游士賢/chatgcp/06 連結] | ||
| + | |||
| + | '''index.php,程式碼如下:''' | ||
| + | <pre> | ||
| + | <?php | ||
| + | // 讀取 XML 檔案 | ||
| + | $xml = simplexml_load_file("numbers.xml"); | ||
| + | |||
| + | // 取出兩個數字 | ||
| + | $num1 = (int)$xml->number1; | ||
| + | $num2 = (int)$xml->number2; | ||
| + | |||
| + | // 計算結果 | ||
| + | $result = $num1 + $num2; | ||
| + | |||
| + | // 回傳結果 | ||
| + | echo "$num1 + $num2 = $result"; | ||
| + | ?> | ||
| + | </pre> | ||
| + | |||
| + | '''numbers.xml,程式碼如下:''' | ||
| + | <pre> | ||
| + | <?xml version="1.0" encoding="UTF-8"?> | ||
| + | <numbers> | ||
| + | <number1>12</number1> | ||
| + | <number2>34</number2> | ||
| + | </numbers> | ||
| + | </pre> | ||
| + | |||
| + | ===範例二、未知兩數,應用php讀取xml數值=== | ||
| + | *說明:使用者自行輸入兩個數字進行加法運算,按下計算按鈕後,系統會顯示計算結果,同時將計算紀錄存入 XML 檔案中。 | ||
| + | *範例程式:[http://jendo.org/~游士賢/chatgcp/05 連結] | ||
| + | |||
| + | '''index.php,程式碼如下:''' | ||
| + | <pre> | ||
| + | <!DOCTYPE html> | ||
| + | <html> | ||
| + | <head> | ||
| + | <meta charset="UTF-8"> | ||
| + | <title>PHP 結合 XML 的算術範例程式</title> | ||
| + | </head> | ||
| + | <body> | ||
| + | <h1>請輸入兩個數字進行運算</h1> | ||
| + | <form action="calculate.php" method="post"> | ||
| + | <label for="num1">第一個數字:</label> | ||
| + | <input type="number" name="num1" id="num1"><br><br> | ||
| + | <label for="num2">第二個數字:</label> | ||
| + | <input type="number" name="num2" id="num2"><br><br> | ||
| + | <label for="operator">運算符號:</label> | ||
| + | <select name="operator" id="operator"> | ||
| + | <option value="+">+</option> | ||
| + | <option value="-">-</option> | ||
| + | </select><br><br> | ||
| + | <input type="submit" value="計算"> | ||
| + | </form> | ||
| + | </body> | ||
| + | </html> | ||
| + | </pre> | ||
| + | |||
| + | '''calculate.php,程式碼如下:''' | ||
| + | <pre> | ||
| + | <?php | ||
| + | // 讀取 XML 檔案 | ||
| + | $xml = simplexml_load_file('result.xml'); | ||
| + | |||
| + | // 取得使用者輸入的數字和運算符號 | ||
| + | $num1 = $_POST['num1']; | ||
| + | $num2 = $_POST['num2']; | ||
| + | $operator = $_POST['operator']; | ||
| + | |||
| + | // 計算結果 | ||
| + | if ($operator == '+') { | ||
| + | $result = $num1 + $num2; | ||
| + | } else { | ||
| + | $result = $num1 - $num2; | ||
| + | } | ||
| + | |||
| + | // 建立新的計算紀錄 | ||
| + | $calculation = $xml->addChild('calculation'); | ||
| + | $calculation->addChild('num1', $num1); | ||
| + | $calculation->addChild('num2', $num2); | ||
| + | $calculation->addChild('operator', $operator); | ||
| + | $calculation->addChild('result', $result); | ||
| + | |||
| + | // 將結果存入 XML 檔案 | ||
| + | $xml->asXML('result.xml'); | ||
| + | |||
| + | // 顯示計算結果 | ||
| + | echo "計算結果:$num1 $operator $num2 = $result"; | ||
| + | ?> | ||
| + | </pre> | ||
| + | |||
| + | '''result.xml,程式碼如下:''' | ||
| + | <pre> | ||
| + | <?xml version="1.0" encoding="UTF-8"?> | ||
| + | <calculations> | ||
| + | </calculations> | ||
| + | </pre> | ||
| + | |||
| + | ==php+json顯示於網頁== | ||
| + | ===範例一、使用者自行輸入兩個數字進行,加減法功能=== | ||
| + | *說明:使用者輸入的兩個數字和運算符號,然後進行加法或減法運算。計算結果存儲在一個 PHP 陣列中,並使用 PHP 內置的 json_encode 函數將其轉換為 JSON 格式的字串。最後,透過設定 Content-Type 為 application/json,回傳 JSON 格式的計算結果。 | ||
| + | *範例程式:[http://jendo.org/~游士賢/chatgcp/07 連結] | ||
| + | |||
| + | '''index.html,程式碼如下:''' | ||
| + | <pre> | ||
| + | <!DOCTYPE html> | ||
| + | <html> | ||
| + | <head> | ||
| + | <meta charset="utf-8" /> | ||
| + | <title>加減法運算</title> | ||
| + | </head> | ||
| + | <body> | ||
| + | <h1>加減法運算</h1> | ||
| + | <form action="calculate.php" method="post"> | ||
| + | <p> | ||
| + | <label for="num1">輸入第一個數字:</label> | ||
| + | <input type="number" id="num1" name="num1" required> | ||
| + | </p> | ||
| + | <p> | ||
| + | <label for="num2">輸入第二個數字:</label> | ||
| + | <input type="number" id="num2" name="num2" required> | ||
| + | </p> | ||
| + | <p> | ||
| + | <label for="operator">選擇運算符號:</label> | ||
| + | <select id="operator" name="operator"> | ||
| + | <option value="+">+</option> | ||
| + | <option value="-">-</option> | ||
| + | </select> | ||
| + | </p> | ||
| + | <p> | ||
| + | <input type="submit" value="計算"> | ||
| + | </p> | ||
| + | </form> | ||
| + | </body> | ||
| + | </html> | ||
| + | </pre> | ||
| + | |||
| + | '''calculate.php,程式碼如下:''' | ||
| + | <pre> | ||
| + | <?php | ||
| + | // 取得使用者輸入的數字和運算符號 | ||
| + | $num1 = $_POST['num1']; | ||
| + | $num2 = $_POST['num2']; | ||
| + | $operator = $_POST['operator']; | ||
| + | |||
| + | // 計算結果 | ||
| + | if ($operator == '+') { | ||
| + | $result = $num1 + $num2; | ||
| + | } else { | ||
| + | $result = $num1 - $num2; | ||
| + | } | ||
| + | |||
| + | // 將計算結果存入 JSON 格式的字串 | ||
| + | $data = array( | ||
| + | 'num1' => $num1, | ||
| + | 'num2' => $num2, | ||
| + | 'operator' => $operator, | ||
| + | 'result' => $result | ||
| + | ); | ||
| + | $json = json_encode($data); | ||
| + | |||
| + | // 設定 Content-Type 為 JSON | ||
| + | header('Content-Type: application/json'); | ||
| + | |||
| + | // 回傳 JSON 格式的計算結果 | ||
| + | echo $json; | ||
| + | ?> | ||
</pre> | </pre> | ||
2025年10月31日 (五) 14:14的最新修訂版本
2025 後
- 每週約來一次
----------向遠哲佩君請款---------- -
第三期申請補助資料櫃 - 領據樣張
- 空白領據
- 李國章的基本資料
- readme.htm
----------列車---------- - 維護手冊
- 維護簡報
- 場次維護介面 / keyman 資料
-
維護嘉義場次參與者資料
----------台灣全社會靭性兩論壇----------
----------辦公室基礎業務---------- -
繳費- 伙伴勞健保:
- 電話 / 頻寬:中華電信
- 水電:自強國中總務處
- 房租:自強國中總務處
-
維護「DS218 / video / 匯款」 -
剪報 -
從黃鈴諭兒子處取回工作帳號 - 網約短約工作平台
- 救 Etherpad
目錄
php+python顯示於網頁
範例一、文字顯示
- 說明:利用 php 讀取 python 檔案,並將文字顯示「Hello, world!」於頁面上。
- 範例程式:連結
index.php,程式碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PHP呼叫Python範例</title>
</head>
<body>
<?php
$output = shell_exec('python word.py'); // 用 shell_exec 函式呼叫 Python 程式並取得輸出
echo "<pre>$output</ pre>"; // 將輸出作為純文本輸出到 HTML 頁面上
?>
</body>
</html>
word.py,程式碼如下:
print("Hello, world!")
範例二、兩數相加算術
- 說明:利用 php 讀取 python 檔案,並使用者將兩個數值填入並按計算,答案將顯示於網頁上。
- 範例程式:連結
index.php,程式碼如下:
<!DOCTYPE html>
<html>
<head>
<title>兩數相加算術範例</title>
</head>
<body>
<h2>兩數相加算術</h2>
<form method="POST">
<label>請輸入第一個數字:</label>
<input type="text" name="num1">
<br><br>
<label>請輸入第二個數字:</label>
<input type="text" name="num2">
<br><br>
<input type="submit" name="submit" value="計算">
</form>
<?php
if(isset($_POST['submit'])){
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$python_path = "/usr/bin/python"; // 設定 Python 可執行文件的路徑
$python_script = "calculate.py"; // 要執行的 Python 腳本路徑
// 執行 Python 腳本,並傳遞數字參數
$command = escapeshellcmd("$python_path $python_script $num1 $num2");
$output = shell_exec($command);
echo "<p>答案:$output</p>"; // 在網頁上顯示 Python 腳本的輸出
}
?>
</body>
</html>
calculate.py,程式碼如下:
import sys # 獲取從 PHP 傳遞的兩個數字參數 num1 = float(sys.argv[1]) num2 = float(sys.argv[2]) # 執行算術操作 result = num1 + num2 # 將結果返回給 PHP print(result)
php+xml顯示於網頁
範例一、已知兩數,應用php讀取xml數值
- 說明:xml 檔案已存在兩位數「12」和「34」,應用php讀取xml檔,將答案將顯示於網頁上。
- 範例程式:連結
index.php,程式碼如下:
<?php
// 讀取 XML 檔案
$xml = simplexml_load_file("numbers.xml");
// 取出兩個數字
$num1 = (int)$xml->number1;
$num2 = (int)$xml->number2;
// 計算結果
$result = $num1 + $num2;
// 回傳結果
echo "$num1 + $num2 = $result";
?>
numbers.xml,程式碼如下:
<?xml version="1.0" encoding="UTF-8"?>
<numbers>
<number1>12</number1>
<number2>34</number2>
</numbers>
範例二、未知兩數,應用php讀取xml數值
- 說明:使用者自行輸入兩個數字進行加法運算,按下計算按鈕後,系統會顯示計算結果,同時將計算紀錄存入 XML 檔案中。
- 範例程式:連結
index.php,程式碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PHP 結合 XML 的算術範例程式</title>
</head>
<body>
<h1>請輸入兩個數字進行運算</h1>
<form action="calculate.php" method="post">
<label for="num1">第一個數字:</label>
<input type="number" name="num1" id="num1"><br><br>
<label for="num2">第二個數字:</label>
<input type="number" name="num2" id="num2"><br><br>
<label for="operator">運算符號:</label>
<select name="operator" id="operator">
<option value="+">+</option>
<option value="-">-</option>
</select><br><br>
<input type="submit" value="計算">
</form>
</body>
</html>
calculate.php,程式碼如下:
<?php
// 讀取 XML 檔案
$xml = simplexml_load_file('result.xml');
// 取得使用者輸入的數字和運算符號
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$operator = $_POST['operator'];
// 計算結果
if ($operator == '+') {
$result = $num1 + $num2;
} else {
$result = $num1 - $num2;
}
// 建立新的計算紀錄
$calculation = $xml->addChild('calculation');
$calculation->addChild('num1', $num1);
$calculation->addChild('num2', $num2);
$calculation->addChild('operator', $operator);
$calculation->addChild('result', $result);
// 將結果存入 XML 檔案
$xml->asXML('result.xml');
// 顯示計算結果
echo "計算結果:$num1 $operator $num2 = $result";
?>
result.xml,程式碼如下:
<?xml version="1.0" encoding="UTF-8"?> <calculations> </calculations>
php+json顯示於網頁
範例一、使用者自行輸入兩個數字進行,加減法功能
- 說明:使用者輸入的兩個數字和運算符號,然後進行加法或減法運算。計算結果存儲在一個 PHP 陣列中,並使用 PHP 內置的 json_encode 函數將其轉換為 JSON 格式的字串。最後,透過設定 Content-Type 為 application/json,回傳 JSON 格式的計算結果。
- 範例程式:連結
index.html,程式碼如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>加減法運算</title> </head> <body> <h1>加減法運算</h1> <form action="calculate.php" method="post"> <p> <label for="num1">輸入第一個數字:</label> <input type="number" id="num1" name="num1" required> </p> <p> <label for="num2">輸入第二個數字:</label> <input type="number" id="num2" name="num2" required> </p> <p> <label for="operator">選擇運算符號:</label> <select id="operator" name="operator"> <option value="+">+</option> <option value="-">-</option> </select> </p> <p> <input type="submit" value="計算"> </p> </form> </body> </html>
calculate.php,程式碼如下:
<?php
// 取得使用者輸入的數字和運算符號
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$operator = $_POST['operator'];
// 計算結果
if ($operator == '+') {
$result = $num1 + $num2;
} else {
$result = $num1 - $num2;
}
// 將計算結果存入 JSON 格式的字串
$data = array(
'num1' => $num1,
'num2' => $num2,
'operator' => $operator,
'result' => $result
);
$json = json_encode($data);
// 設定 Content-Type 為 JSON
header('Content-Type: application/json');
// 回傳 JSON 格式的計算結果
echo $json;
?>