Web Spider using php cli

Purely on academic basis, I had once helped to cook up a web spider, which is used to build site maps. The spider was written in php and uses a couple of reg-exp matches, and finally writes the full sitemap from the start url. The system is assembled using two classes, WebPage and WebSpider. Then to make it similar to linux utilities in the command line environment, some functions were scooped in.
Continue reading “Web Spider using php cli”

User input in php command line

Ever wondered how to capture the user input when writing php command line scripts ?

<?php
 
function getInput($msg){
  
fwrite(STDOUT"$msg: ");
  
$varin trim(fgets(STDIN));
  return 
$varin;
}
 
?>

The function above is being used by me in certain command line scripts, where I need user responses.