php - how to load properly sql data with a new line -
im trying query database , when im using code below, repeats part of data
$data = $result['testdata']; $data = str_replace("\r\n", "<br>", $data); $data = str_replace("\r", "<br>", $data); $data = str_replace("\n", "<br>", $data); echo "<form action='testsearch.php' method='post'>"; echo"<tr>"; echo "<td align='center' width='auto'>" . $result['test'] . "<input type=hidden name=test value=" . $result['test'] . "' /> </td>"; echo "<td align='left' width='500'>" . $data . "<input type=hidden name=testdata value=" . $data . "' /> </td>"; "</tr>"; here snapshot of result of code above:
now when seek utilize htmlentities in code resolve issue im losing new line , beingness replace instead <br>
$data = $result['testdata']; $data = str_replace("\r\n", "<br>", $data); $data = str_replace("\r", "<br>", $data); $data = str_replace("\n", "<br>", $data); $data1 = htmlentities($data); echo "<form action='testsearch.php' method='post'>"; echo"<tr>"; echo "<td align='center' width='auto'>" . $result['test'] . "<input type=hidden name=test value=" . $result['test'] . "' /> </td>"; echo "<td align='left' width='500'>" . $data1 . "<input type=hidden name=data1 value=" . $data1 . "' /> </td>"; "</tr>"; here snapshot of sec code:
i need help in maintaining new line , @ same time not repeating datas fetch mysql db...
you're missing quotes @ origin of value attributes. , need convert html special characters entities only when they're within attributes, not in text. should be:
echo "<td align='center' width='auto'>" . $result['test'] . "<input type=hidden name=test value='" . htmlspecialchars($result['test']) . "' /> </td>"; echo "<td align='left' width='500'>" . $data . "<input type=hidden name=data1 value='" . htmlspecialchars($data) . "' /> </td>"; php html mysql
No comments:
Post a Comment