0
$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.

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by vibhaJ
0

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

0

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?

0

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.

0
<?
	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]);
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.