在 php 字符串中放置一个 lang 函数
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>";
所以Select,按签名字符过滤,然后翻译。
现在,我有一个包含翻译的 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']);
正在尝试将我的 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>";
所以Select,按签名字符过滤,然后翻译。
现在,我有一个包含翻译的 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']);