Sure, here are some examples. I have a database table with two rows: Green & Red. I'm parsing through text files and looking for the first line in the file that contains either Green or Red, then I want to include the entire line in a form to submit to the database.
colors: Array ( [0] => Green [1] => Red )
File Contents:
Green Line
Testing Value
Black & White
Nothing Good
In this example, I'd like to identify the first line of the file as $file[0]=> Green Line.
Does that help? Here's the full code, right now it's just echoing out stuff as I'm trying to figure out how I should go about this:
<?php
include 'connection.php';
include 'header.inc.php';
include 'connect_ftp.inc.php';
$query_color = "select color,color_id from colors";
$results_color = mysql_query($query_color) or die(mysql_error());
while($row = mysql_fetch_array($results_color)){
$color[] = $row['color'];
sort($color);}
// get contents of the current directory
$contents = ftp_nlist($conn_id, $ftp_dir.$_GET['dir']);
foreach ($contents as $v) {
if (strpos($v, "test.txt") !== false) {
$trimmed = substr($v,$ftp_dir_len);
$file = array_map('rtrim',file('ftp://'.$ftp_user_name.':'.$ftp_user_pass.'@'.$ftp_server.'/'.$v));
// search for green/red lines
foreach($color as $x){
$color_str = preg_grep("/".$x."/",$file);
}
echo "color_str: ";
print_r($color_str);
echo "<br>colors: ";
print_r($color);
echo "<br>File: ";
foreach ($file as $w){
echo "<br>".$w;
}
}}
?>