-
[php] online notepad
my email got messed up with too many things i had to remind so i made this
PHP Code:
<?php
$file = 'note.txt';
if(isset($_GET['info'])){
$files = fopen($file,'w');
fwrite($files, $_GET['info']);
fclose($files);
}
?>
<html>
<body>
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Sorry, Notepad will not work with your browser.");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
}
}
var info = nl2br(document.notepad.textarea.value, false);
ajaxRequest.open("GET", "<?php echo $_SERVER['PHP_SELF']; ?>?info=" + info, true);
ajaxRequest.send(null);
}
function nl2br (str, is_xhtml) {
var breakTag = '';
var extra = true;
breakTag = '<br />';
if (typeof is_xhtml != 'undefined' && !is_xhtml) {
breakTag = '<br>';
}
if(extra == true){
breakTag = '%br%';
}
return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}
//-->
</script>
<div align='center'>
<form name='notepad'>
<textarea onKeyUp="ajaxFunction();" name='textarea' cols='150' rows='40'>
<?php
$a = file_get_contents($file);
echo str_replace('%br%', '
', $a);
?>
</textarea>
</form>
</div>
</body>
</html>
(sorry if there is any useless code, my own website uses it with mysql)
The funny thing is, no save buttum due ajax = great!