- I have PHP searching in a text file for packages and then it prints back the information. I have a working script but it only works if the user types in the name of the package correctly and uses any captailization that the item has in the file. How can I make PHP less strict about this? Like, a user spelling the word slightly wrong, or forgetting a "-".
- Below is another script I'm working on for getting information from a file. My objective is for the script to grab the first line and the third line, not the second. The file contents of the PACKAGES.TXT look something like this:
PACKAGE NAME: asdf PACKAGE SIZE: 8k PACKAGE LOCATION: www.asdf.com/asdf-package.html
At the moment, I'm using this to gather that information, but it's simply not working with the first and third lines:
$data4 = file('www.asdf.com/PACKAGES.TXT'); //the text file above
for ($i = 0, $found = FALSE; isset($data4[$i]); $i++) { //$i is the counter.
/*$package2 consists of the word searched and a constant string: "PACKAGE NAME: */
if (trim($data4[$i]) === $package2) {
$fdas = trim($data3[++$i]); //$fdas is going to hold the url info
echo ($find2); //$find2 is the original package name.
echo("<br/>"); //two breaks
echo("<br/>");
//the lines below handle making a link from a URL and custom package location
$finout = strstr($fdas, '.'); //
$secondfinout = "http://www.asdf.com/".$finout;
echo("<a href='$secondfinout'>$secondfinout</a>");
$found = TRUE;
break;
}
}
The second step is script I'm writing now. It doesn't work. I do have simpler ones that follow the same concept that do work, the only problem is the strstr($fdas,'.'); puts a dot in the url. I had to start the string somewhere and leave out the parts that are not apart of the url and the dot seems to be my only choice, is there a way I can remove of it?
Thank you so much for any input, I understand this a lengthy question, so feel free to answer what you want of it. I should note that the php script is started by an javascript/html form and then the POSTs are passed to PHP. I am sure those all work right.
Thank you.