Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-02-2008, 03:29 AM   PM User | #1
ramki067
New Coder

 
Join Date: Oct 2007
Posts: 90
Thanks: 2
Thanked 0 Times in 0 Posts
ramki067 is an unknown quantity at this point
Problems finding a pattern in a line.Please help.

Hi,
I need to search a pattern in each line of a file and if that pattern found then it should extract that complete line from the file and write it to another file. I've written the code but it not working!Please help. $Data is getting the data. $pattern is present in that file which i checked it out manually.Is my searching correct?


Code:
$handle = fopen($Filename, 'r');
$File1 = "Automation_streams.txt";
$Handle1 = fopen($File1, 'w');
$d=0;

while(!feof($handle))
{ 
	$Data = fgets($handle,1024);
	$pattern = $stream_names[$d];
	if(preg_match($pattern,$Data)!=0)
	{
		echo "Matched data is $Data<br>";
		fwrite($Handle1,$Data);
		$d++;
		print "<p>";
	}
	
}
The pattern to be searched is like this:

Code:
"test1_WMA_40_v2_128kbps_48kHz_2"
and the file contains these type of names as below:

Code:
settop decode -audio 0x1 -mpeg_type ASF -audio_type 0x86 /wma/L2/WMA_V4.0/test1_WMA_40_v2_128kbps_48kHz_2.asf	test1_WMA_40_v2_128kbps_48kHz_2	C:\Audio_Regress\recorded_files	90	48000


Thanks,
Ramki.
ramki067 is offline   Reply With Quote
Old 03-02-2008, 09:41 AM   PM User | #2
digitalfiz
New Coder

 
Join Date: Mar 2008
Location: Lakeland, FL
Posts: 39
Thanks: 1
Thanked 3 Times in 3 Posts
digitalfiz is an unknown quantity at this point
I think you need to delimit the underscores when using regexp. you also need a slash in front and back of the pattern.

PHP Code:

$pattern 
str_replace("_""\_"$stream_names[$d]);
$pattern "/".$pattern."/"
digitalfiz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:39 AM.


Advertisement
Log in to turn off these ads.