0

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>\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
5
  • 2
    echo the variable after str_replace not before. Commented Apr 19, 2013 at 17:53
  • thanks, but that is not the issue, as it appears Commented Apr 19, 2013 at 18:03
  • Can you elaborate more on this ? Its bit confusing. What you want to accomplish ? Commented Apr 19, 2013 at 18:09
  • I updated my post a bit. Commented Apr 19, 2013 at 18:15
  • 1
    You are changing the array and not the value in the table. If you will fetch the reagent_no from table you will get markup. Commented Apr 19, 2013 at 18:26

2 Answers 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";
}
Sign up to request clarification or add additional context in comments.

Comments

1

The problem is that the str_replace is executed after the echo.

Try:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.