dsio68964998 2013-04-19 17:51
浏览 12

带有关联数组的PHP str_replace

I have a row returned from DB and i need to change the specific markup characters used in cols to the right characters for the display:

$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 now its getting more weird. I did a mistake by tracing if the str_replace before the change was made to array, i fixed it ant tracing shows that it works! But there is a specialised output of this array down below and it still appears with unreplaced characters!

    $reagent_no = "reaction_l" . $i; // determining the column number, irrelevant to the issue
    echo "<td>
<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
  • 写回答

2条回答 默认 最新

  • dongyuli4538 2013-04-19 17:56
    关注

    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";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000