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

Status
Not open for further replies.

skibascott

IS-IT--Management
Joined
Mar 18, 2004
Messages
82
Location
US
When a user selects a document, I need a list of videos that correspond with the selected doc. The document number is exactly the same as the first part of the filenames of the videos. Here is my code:

Code:
<?php 
			$list = "cd /mnt/sc_proc/video; ls *.wmv | sort"; //list of video clips
			exec($list,$file_list);    
	    
			$phpdocnum = $_POST['PHPdocNum']; 
			$phpdocnumtitle = $_POST['DocNum'];								for($i=0; $i<count($file_list); $i++){ 
								$strlength = strlen($phpdocnum);
			
								if ($phpdocnum == substr($file_list[$i],0,$strlength)){
								echo $file_list[$i];
								}else{
								}
			}					
?>

My goal right now is simply to display a list video files that have filenames corresponding to the selected document. The output of the above code does not display the matches. Any suggestions?
Thank you.
 
It's difficult to say without knowing what values are being passed into the script.


More general questions...

Is $file_list being populated as you expect?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ok, I have figured out why the comparison is not yielding any results. $file_list is being populated as I expect, with the names of the video files in the specified directory. The value that I am passing into the script, $phpdocnum, is the document that is selected by the user. For example, $phpdocnum value is 4.00.03, the code should then output a list of video file names that begin with 4.00.03(there will be multiple files that begin with that string). The problem is that the names of the video files that correspond to doc# 4.00.03 are actually named 4.00-3. I cannot rename the files because they are in use by other web applications. How can modify my IF statement to yield the desired results(ie. return filenames beginning with 4.00-3 when the user selects doc# 4.00.03?

Thank you for the help.
 
What is the source of the values in $_POST['PHPdocNum']? Is this a dropdown list, or is this some value a user is typing in?

If the former, the easiest thing to do in the long run will be to modify the source of the values in the dropdown to better match your filenames.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Yes, it is a dropdown list. I wish I could just modify the filenames. The thing is, they are corporate standards and I cannot change the document numbers. I could change the filenames of the videos, but like I said they are being used by other applications. If there is no other solutions, I will copy the videos to a new directory and change the filenames. There is over 150 videos, so it would be a lot of work to change the names. I was hoping that I could modify my comparison statement through the use of regular expressions. But, since I just started using php and do not have much programming experience my attempts to understand regular expressions has only given me a massive headache. Any other suggestions, I surely appreciate your help.
 
what about str_replace or preg_match to change the second period to a hyphen?




Bastien

Cat, the other other white meat
 
Just out of curiosity, how did your company's data and files get so out-of-sync?


It is indeed possible to use regular expressions to map one filename type to another. And I can help you with that....

but I do not know enough about your data to be able to help you with the information you've given.

Can you describe how someone would match the values to filenames if he were doing it by hand?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Sleipnir214, I don't know why the data is out of sync. I just started here and the person that did all of this work before me left no documentation behind.
I think that Bastien's suggestion could help though. I will look into using the str_replace method.

Thank you for all of the help. It is good to know that there are still things in life for free.
Peace.
 
str_replace() is probably not the function you need to use. It will change all the periods to dashes.

If each string is like the one example, that is "one or more digits, followed by a dot, followed by one or more digits, followed by a dot, followed by one or more digits" and that the second dot and the second dot only must be changed from a dot to a dash, I can off the top of my head think of two ways to do it:

Using preg_replace():

<?php
$a = '4.00.3';
$b = preg_replace ('/^(\d+\.\d+)\.(\d+)$/', '$1-$2', $a);
print $b;
?>


Using explode() and building the string by-hand:

<?php
$a = '4.00.3';
$b = explode ('.', $a);
$b = $b[0] . '.' . $b[1] . '-' . $b[2];
print $b;
?>






Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top