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.
You can enforce case on the comparison:
if (strtolower(trim($data4[$i])) === strtolower($package2)) {
or do some real-world enforcement, like running people through a woodchipper if they enter bad-cased data. Workers are plentiful these days and are generally disposable, so seeing fellow data-entry people getting turned into ketchup should promote a general feeling of workplace satisfaction.
1) you can use regular expressions, and preg_replace. Regular Expression References
2) I think if you want the first and third line of a txt document, you can use the following code:
$data4 = file('www.asdf.com/PACKAGES.TXT');
$firstLine = $data4[0]; //PACKAGE NAME: asdf
$thirdLine = $data4[2]; //PACKAGE LOCATION: www.asdf.com/asdf-package.html
3) If you want to get the URL from the third line, you could just find the forward slash with preg_match:
preg_match('/\/(\S+)/',$thirdLine,$finout);
$secondfinout = "http://www.asdf.com/".$finout[1]; //take the second value in the newly created $finout array, which is asdf-package.html
Hope that answers everything. :)