Skip to main content

Posts

Showing posts from April, 2012

How to sort a file content alphabetically/ numerically using PHP with Linux command

Code <?php class sortFile { function sort ( $file ) { exec ( "cat > temp.txt" ); // Create a temp file exec ( "chmod 777 temp.txt" ); // Give permission for temp.txt exec ( "sort -k1 " . $file . " > temp.txt" ); // sort the first column(k1) of test.txt and save to temp.txt exec ( "rm test.txt" ); // delete test.txt exec ( "mv temp.txt " . $file . "" ); // rename temp.txt to test.txt } } $sortfile = new sortFile(); $sortfile -> sort ( "test.txt" ); ?>

JavaScript Auto Refresh

Demo Create a HTML page with the below code & the page will refresh every 5 seconds. Code <script type="text/JavaScript"> timedRefresh(5000); function timedRefresh(timeoutPeriod) { setTimeout("location.reload(true);",timeoutPeriod); } </script> <p>This page will refresh every 5 seconds. We are passing in the value '5000', which equals 5 seconds.</p>