Last active
May 6, 2019 18:59
-
-
Save Eddy-Barraud/588cdb79beb82dbc634e8f378c954b21 to your computer and use it in GitHub Desktop.
Sample for converting textarea containing links with php & ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$q = trim($_POST["q"]); | |
$lines = explode(PHP_EOL, $q); | |
$result = ""; | |
foreach ($lines as $key => $value) { | |
$result .= $value . PHP_EOL; | |
} | |
echo $result; | |
exit; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
function showHint(str) { | |
if (str.length <= 2) { | |
document.getElementById("txtHint").innerHTML = ""; | |
return; | |
} else { | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function () { | |
if (this.status == 200) { | |
document.getElementById("txtHint").innerHTML = this.responseText; | |
} | |
} | |
xmlhttp.open("POST", "gethint.php", true); | |
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
var params = 'q=' + escape(str); | |
xmlhttp.send(params); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<center> | |
<h1>Link Converter</h1> | |
<textarea rows="20" cols="150" onkeyup="showHint(this.value)"></textarea> | |
<p><textarea rows="20" cols="150" id="txtHint"></textarea></p> | |
</center> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment