Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string comparison problems 1

Status
Not open for further replies.

skibascott

IS-IT--Management
Joined
Mar 18, 2004
Messages
82
Location
US
My goal here is to compare $phpdocnum (selected from a select list on the previous page)with the contents of $file_list. When executing the code here, my foreach loop finds no matches, even though I can see the value of $phpdocnum is exactly the same as a number of values in the $file_list(I have previously confirmed with an echo command the contents of $file_list). Funny thing is, when I manually declare the value of $phpdocnum to a value that I know is in $file_list, I get the desired results(a list of values in $file_list that match the string of $phpdocnum). Why is it that when I specify the value of $phpdocnum I get matches, but when I use the value I am getting from POST I do not get matches. I have confirmed that they hold the same value.

Code:
$list = "cd /mnt/sc_proc/video; ls *.wmv | sort"; 
exec($list,$file_list);    
	    
$phpdocnum = $_POST['PHPdocNum']; 
$phpdocnum = substr_replace($phpdocnum, '-', 4, 1);
$phpdocnum = substr_replace($phpdocnum, '', 5, 1);

echo $phpdocnum."<br>";

foreach ($file_list as $value){
       	if ($phpdocnum == substr($value, 0, 6)){
	echo $value."<br>";
	}
	}
 
Oh gosh, the mnt/sc_proc/video/ path worked. I know I used it tried it before, but for one reason or another, I dismissed it as a failure. So now I have a list of the filenames. The output also includes the path of the filename. I need to get rid of that to be able to compare with $phpdocnum. I am about to work on that now, and I should be able to figure it out. You can rest assured that I will be coming back with more questions. I appreciate all of the help you have given me and apologize for the wild goose chase I led you on with that directory path.
 
One more tip:

Forget the matching of a substring taken from the top of the filename. Use strstr().
If you want to stay with the == method then prepend the path to the $phpdocnum.

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top