[英]Put a lang function inside of a php string
嘗試將我的MySQL數據庫轉換為PHP。
這是代碼:
$sql = "SELECT Name, Price FROM utf WHERE Name LIKE 'K%'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<div class=\"CSSTableGenerator style=\"width:600px;height:150px;\"><table><tr><th>Name</th><th>Price</th></tr></div>";
// output data of each row
while($row = $result->fetch_assoc()) {
$name = str_replace('K', 'Karambit', $row['Name']);
echo "<tr><td>".$name."</td><td>".$row["Price"]." ".$row["Trend"]."</td></tr>";
}
echo "</table>";
因此,請選擇“按簽名字符過濾”,然后進行翻譯。
現在,我有一個包含翻譯的lang.php文件。
這里是:
<?php
function lang($phrase){
static $lang = array(
'ba' => 'Bayonet',
'ka' => 'Karambit'
);
return $lang[$phrase];
}
?>
我如何把它放在這一行:
$name = str_replace('K', 'Karambit', $row['Name']);
並將'ka' => 'Karambit'
替換為'Karambit'
?
這些都不起作用:
//attempt 1
$name = str_replace('K', 'lang('ka');', $row['Name']);
//attempt 2
$name = str_replace('K', '$lang('ka');', $row['Name']);
//attempt 3
$word = echo lang('ka');
$name = str_replace('K', '$word', $row['Name']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.