$lines = file('http://www.adexmart.com/product.php?id_product=276&utm_source=shopmania&utm_medium=cpc&utm_campaign=direct_link');

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) 
{
    if(htmlspecialchars($line)=="</div> ");
     echo htmlspecialchars($line)."<br>";
}
	
?>

I am printing lines (all html code) successfully, but I dont able to check a condition for a line.
How I can check condition in for loop.

There is ';' after if condition line# 6.Remove it.
What you exactly want?
you want to replace </div> with <br> tag?

Thanks for the reply

I have to fetch a line and then extract some data from that line.

For example:
I need to read the below line and then get 2,990.00 which is vary .
<span id="our_price_display"> Rs 2,990.00</span>

There is ';' after if condition line# 6.Remove it.
What you exactly want?
you want to replace </div> with <br> tag?

You mean it is not fix what you want to read from line?
You can use preg_match function to fetch data using regular expression.

Suppose I want to search the line <span class="our_price_display"> which is fixed, how I check the condition in loop ??

You mean it is not fix what you want to read from line?
You can use preg_match function to fetch data using regular expression.

<?
	echo '<strong>Data is below:</strong>';
	echo $str = 'This is first line.<br>
	   <span id="our_price_display"> Rs 2,990.00</span>
	   This is second line.<br> 
	   <span id="our_price_display"> Rs 17.00</span> ';	
	$pattern = '/span/';
	$pattern = '/<span id="our_price_display">([^"]*)<\/span>/';
	preg_match_all($pattern, $str, $matches);	
	
	echo '<br>This is filtered:<pre>';
	print_r($matches[0]);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.