Find Match and Print Position

Discussion in 'PHP' started by highborn, Apr 15, 2008.

  1. #1
    Hi, Can anyone help me about this problem?
    
    
    I have this file (ex. file.txt) which contains 
    yahoo.com
    google.com
    msn.com
    alexa.com
    
    I want to search the file using php and output the search with its position.
    
    For example, I want to search the file for msn.com 
    and then the script will output 
    
    "Your search for msn.com is found on position number 3"
    
    
    Code (markup):
    How can I make this work on PHP?

    Thanks in advance,

    Highborn
     
    highborn, Apr 15, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Grab the data using file(), trim it, and use array_search to find the position.

    Jay
     
    jayshah, Apr 15, 2008 IP
  3. highborn

    highborn Active Member

    Messages:
    184
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Thanks for your reply, Can you put an example code here that I can look at?
     
    highborn, Apr 15, 2008 IP