Thread: extract text between two strings
Results 1 to 3 of 3
Related
-
Using Javascript, How do I display strings? Forum: Javascript Forum
Replies: 1 -
Help, generate all possible strings with Perl Forum: CGI Perl Forum
Replies: 1 -
extract, sort and compare Forum: CGI Perl Forum
Replies: 2 -
Extract References while connecting to an https server using NNTP perl Forum: CGI Perl Forum
Replies: 0 -
How to get my page content text to show up before navigation text for improved SEO Forum: HTML Forum
Replies: 0
-
11-16-2007, 12:11 PM #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
-
11-23-2007, 03:10 PM #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($handle, filesize($file));
fclose($handle);
$between=substr($contents, strpos($contents, $word1), strpos($contents, $word2) - strpos($contents, $word1));
echo $between;
Bruce
-
12-14-2007, 11:38 PM #3
Re: extract text between two strings
you can also use php split function check it here http://www.php.net/split
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum