3
05/11/2024 8:41 am
Argomento iniziale
- Write a PHP script that sorts the text lines from a <textarea>
- Split by new line "\n". Warning: '\n' does not work!
- Remove \r and spaces when exist
- Sort as string values
- Warning: '\n' will not work!
- Never put space between <textarea> e </textarea>
1 risposta
2
05/11/2024 8:42 am
Here is the code (NOTE: line #18):
<!DOCTYPE html>
<html>
<head>
<title>Sort Lines in PHP</title>
</head>
<body>
<?php
if (isset($_GET['lines'])) {
$lines = $_GET['lines'];
$lines = explode("\n", $lines);
$lines = array_map('trim', $lines);
sort($lines, SORT_STRING);
}
?>
<form>
<div><textarea rows="10" name="lines"><?php if (isset($lines)) echo implode("\n", $lines) ?></textarea></div>
<div><input type="submit" value="SUBMIT"></div>
</form>
</body>
</html>
