SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get a token in a file

    Sir,
    i am having a file i want to take a specify token from tyhat file how can i?

    Example imy file it tt.txt and i am having

    " adnbd asjha arun123 aksja;l"

    i want to extract arun123 how can i
    Arunkumar
    Where there is a will there is a way
    ArunKumar

  2. #2
    SitePoint Addict phpster's Avatar
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    regex, stristr, positional data with substr...take your pick
    phpster

    I wish my computer would do what I want it to.
    Not what I tell it to do...

  3. #3
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sir,
    i tried stristr
    my code was
    $handle = fopen("test.txt", "r+");
    while (!feof($handle)) {
    $buffer = fgets($handle, 4096);
    if($buffer == "arun123")
    $domain = stristr($buffer, 'arun123');
    echo "..........".$domain.";;;;;;;;;;;";
    }
    fclose($handle);
    it is not working
    Arunkumar
    Where there is a will there is a way
    ArunKumar

  4. #4
    SitePoint Addict phpster's Avatar
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    PHP Code:
    $handle fopen("test.txt""r+");
        while (!
    feof($handle)) {
        
    $buffer fgets($handle4096);
            if {
    stristr($buffer,"arun123")){
                
    $domain stristr($buffer'arun123');    
            echo 
    "..........".$domain.";;;;;;;;;;;";    
        }
        
    fclose($handle); 
    cuz this line:
    if($buffer == "arun123")

    will never evaluate properly since yuou can't compare a chunk of a string to an entire string and hope to get a match...
    phpster

    I wish my computer would do what I want it to.
    Not what I tell it to do...


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
  •