Simple Question: Reading exec(locate) results into an array

From: Date: Wed, 27 Apr 2005 20:25:20 +0000
Subject: Simple Question: Reading exec(locate) results into an array
Groups: php.general 
Request: Send a blank email to php-general+get-214040@lists.php.net to get a copy of this message
Hello all, I'm sure this is very rudimentary, sorry if this sounds ignorant. I've only dabbled a bit in other languages and I'm working with a small knowledge of php since I only use it on-and-off at my job. I scribbled up this script today at work off the top of my head for a customer who was looking for a printout of my company's PEAR location. I wanted something quick and easy that would be adaptable to find other items. I was surprised it even worked since I haven't really had a chance to dig into PHP yet: <?php $temp = exec("which pear"); $temp2 = exec("locate pear"); echo "which = $temp <BR><BR> locate = $temp2"; ?> When executing the commands directly within Unix, without the php script: 'which' yields 1 line: the path to the pear module for PHP 'locate' yields dozens of lines, paths to everything with 'pear' in it. However, this is the printout when running the script from a browser (same via command line) : --- which = /usr/local/bin/pear locate = /usr/ports/www/pear-HTTP_Upload/pkg-descr --- It's only printing out a single line for locate. I'm assuming i'd need to run a loop to read all the lines of locate from an array. My question is: what sort of general syntax can I use to get the results from locate stored in an array so it can be read out? I don't need a script written for me; a general nudge in the right direction or the right website would be incredibly helpful. I've had trouble finding anything relevant thus far. Thanks! -Karl

« previous php.general (#214040) next »