0

我有一行从 DB 返回,我需要将 cols 中使用的特定标记字符更改为显示的正确字符:

$row = mysqli_fetch_array($res, MYSQLI_ASSOC); //the result of query is 1 row

$markup = array("@", "#", "&", "$"); // this is our markup
$meaning   = array("↑", "↓", "(dil.)", "(conc.)"); // this is our meaning of the markup for the display

foreach ($row as $k => $v) { //for each element of the array we change one char for the other
$v = str_replace ($markup, $meaning, $v);
echo "<br>$v";

}

UPD 现在变得越来越奇怪了。如果在对数组进行更改之前跟踪 str_replace,我犯了一个错误,我修复了它,蚂蚁跟踪表明它有效!但是下面有这个数组的特殊输出,它仍然出现未替换的字符!

    $reagent_no = "reaction_l" . $i; // determining the column number, irrelevant to the issue
    echo "<td>\n<h3>{$row[$reagent_no]}</h3></td>"; //output of the supposedly 
//changed characters, but it still outputs the markup, as if i didnt do anything to the array previously
4

2 回答 2

1

You are first printing the variable and then using the str_replace() function. Change it to:-

foreach ($row as $k => $v) { //for each element of the array we change one char for the other
$v = str_replace ($markup, $meaning, $v);
echo "<br>$v";
}
于 2013-04-19T17:56:51.507 回答
1

问题是str_replaceecho.

尝试:

foreach ($row as $k => $v) { //for each element of the array we change one char for the other
    $v = str_replace ($markup, $meaning, $v);
    echo "<br>$v";
}
于 2013-04-19T18:01:10.647 回答