简体   繁体   中英

How to array(per line) textarea

Good morning! Please some body help or give some sample code about how to read text value (per line)

<body onLoad="displayResult()">
<table align="center">
<tr>
<td>
<?php $query2="SELECT * FROM upload1 WHERE NAME='xmlsample1.xml'";
$result1=mysql_query($query2);
$row = mysql_fetch_array($result1);
?>
<form action="">
<textarea id="validxml" rows="50" cols="100">
<?php echo $row['CONTENT']; ?>
</textarea>

<br><br>
<input type="button" value="Verify XML" onClick="validateXML()" />

</form>
</td>
</tr>
</table>
</body>

Access the value of textarea and split newline

console.log(document.getElementById('validxml').value.split("\n"));

JSFiddle

connect.php should be kept on a separate, secure web page.

<?php 
function db(){
  return new mysqli('host', 'username', 'password', 'database');
}
?>

Now on your other page:

<?php 
include 'connect.php'; $db = db();
$sq = $db->query("SELECT * FROM upload1 WHERE name='xmlsample1.xml'"); $ta = '';
if($sq->num_rows > 0){
  while($row = $sq->fetch_object()){
    $ta .= "<textarea class='validxml' name='{$row->name}'>{$row->content}</textarea>";
  }
}
$sq->free(); $db->close();
?>

Now just echo $ta into your HTML. Of course, I wouldn't even use a <textarea> to just output code, unless you want your user to be able to edit it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM