35 users online (2 members and 33 guests)  


  Results 1 to 3 of 3

Related

  1. Using Javascript, How do I display strings?    Forum: Javascript Forum
    Replies: 1
  2. Help, generate all possible strings with Perl    Forum: CGI Perl Forum
    Replies: 1
  3. extract, sort and compare    Forum: CGI Perl Forum
    Replies: 2
  4. Replies: 0
  5. Replies: 0
  1. #1
    shishir's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2007
    Posts
    1

    extract text between two strings

    hi,

    This is Shishir Agarwal. I am facing a major problem.
    I want to extract text between two strings from a text file. I have no idea how to do it. please help me to solve my problem. my mail id is shishir76@gmail.com.

    thanks,
    Shishir Agarwal

  2. #2
    Bruce_KD's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2007
    Location
    Delaware, USA
    Posts
    2

    Re: extract text between two strings

    I'm assuming by the text between two string you mean something like

    'Hello. I like to write code in php. It is a lot of fun.'

    The words would be 'like' and 'lot'.

    PHP Code:
    //First, open the file. Change your filename
    $file "file.txt";
    $word1='like';
    $word2='lot';


    $handle fopen($file"r");
    $contents fread($handlefilesize($file));
    fclose($handle);

    $between=substr($contentsstrpos($contents$word1), strpos($contents$word2) - strpos($contents$word1));

    echo 
    $between

    Bruce

  3. #3
    edpudol's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2007
    Posts
    5

    Re: extract text between two strings

    you can also use php split function check it here http://www.php.net/split



Tags for this Thread