SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    search text file position

    I have a text file which contains the word "Profile", I can write an algorithm to use the strpos to detect the word "Profile" found or not, if found, i need the position of the word, how to determine the position of the word ? I need the position is because from there onwards, I would like to go for character by character to check and do some convertion, Any idea, please help.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    strpos

    strpos - "string position"
    Although this function is often used to determine simply whether or not the needle string is in the haystack:
    Returns the numeric position of the first occurrence of needle in the haystack string.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes of course strpos() function will work for finding whether a string is in the document or not and returns the position of the string from the beginning. What you mean search character by character and do some conversion? Do you want to make replacing the found string/character. If the file is too big then it would be slower to go for character by character as i think so far.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the text file, after the words "Profile", it contains 250 lines, which it actually is 250 records with 15 data, each data was seperate by a ",".
    I need to read character by character to check for "," and chr(13) to determine that is end of each record. the word "Profile" will be found somewhere in the text file, and after that it is records. Is there any easy method for me to read each record ? each records with readings I need to do some calculation like multiply with radius and etc...

    muchly appreciate for any reply....

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    csv + file

    So the file is essentially a csv file with a text lead in? I would read the file to a string, use strpos() to find the beginning of the csv portion, then maybe use str_getcsv(). Or split() if the function isn't live yet http://www.php.net/manual/en/function.split.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •