Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > PHP

Reply
 
LinkBack Thread Tools
Old July 31st, 2010, 04:46 PM   #1
New Member
 

Join Date: Jan 2008
Location: Reykjavik
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 skuliaxe is on a distinguished road
Search CVS file for string, canīt make it work

I have a CVS file and a user input field that I need to see if it exists in that CVS file.

Here is what Iīm using, but I canīt get it to work:
Code:
$input $_GET["input"];  

# Open the File.  
    
if (($handle fopen("http://www.skuli.us/cvs/demo.cvs""r")) !== FALSE) {  
        
# Set the parent multidimensional array key to 0.  
        
$nn 0;  
        while ((
$data fgetcsv($handle1000",")) !== FALSE) {  
            
# Count the total keys in the row.  
            
$c count($data);  
            
# Populate the multidimensional array.  
            
for ($x=0;$x<$c;$x++)  
            {  
                
$csvarray[$nn][$x] = $data[$x];  
            }  
            
$nn++;  
        }  
        
# Close the File.  
        
fclose($handle);  
    }  
      
    if (
in_array($input$csvarray)) { die('Found');  }  
    else { echo 
$input; die('Not found'); } 
Even if I type in "1" as the input I get Not Found
I would like to find the exact match to the user input.
skuliaxe is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 3rd, 2010, 07:41 AM   #2
New Member
 

Join Date: Aug 2010
Location: Earth
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 bigmax is on a distinguished road
Re: Search CVS file for string, canīt make it work

Try
Code:
$file = file("yourcvs.cvs");
$num = 1;
foreach ($file as $line) {
$one_line = explode(",",$line);
if (in_array($your_input,$one_line)) {
echo "found $your_input in line number $num";
}
$num++;
}
bigmax is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 2nd, 2010, 08:57 AM   #3
New Member
 

Join Date: Jan 2008
Location: Reykjavik
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 skuliaxe is on a distinguished road
Re: Search CVS file for string, canīt make it work

Quote:
Originally Posted by bigmax View Post
Try
Code:
$file = file("yourcvs.cvs");
$num = 1;
foreach ($file as $line) {
$one_line = explode(",",$line);
if (in_array($your_input,$one_line)) {
echo "found $your_input in line number $num";
}
$num++;
}
I got some help with this from the devshed and here is what worked perfectly for me:
Code:
$found false
if (
$handle fopen("http://www.domain.com/csv/demo.csv""r")) { 
    while (
$data fgetcsv($handle1000",")) { 
        
$csvarray[] = $data
        if (
$data[0] == $_GET["input"]) { 
            
$found true;
            break; 
// Stop searching if match is found
        

    } 
    
fclose($handle); 


if (!
$found) echo "NO"
Thank you for your contribution.
skuliaxe is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you help me make this STR_REPLACE to work? ruffy PHP 2 July 23rd, 2008 05:06 PM
Change a string of characters with aonether in a HTML file r3ticul JavaScript 4 January 21st, 2008 05:28 AM
http post xml string and binary file in multipart message pezkel Classic ASP 0 June 10th, 2007 04:12 AM
How to make XML file work with slide show player OmiE Your Design and Layout 0 June 4th, 2007 05:49 PM
How make Word file same as html file in ASP humair Classic ASP 5 September 24th, 2003 10:35 AM


Search Engine Optimization by vBSEO 3.2.0 RC8