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 01-23-2013, 04:52 AM   PM User | #1
mac34
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mac34 is an unknown quantity at this point
Question Confusion with preg_match for Specific DIV can anyone help me?

Can anyone tell me how to fetch all data in specific DIV and inside it is specific Tag " <p></p>" of given url

I Tried this but changing tag names but i Failed please any php expert can me help me ?

<?php

function getdata($Url){
$str = file_get_contents($Url);
if(strlen($str)>0){
preg_match("/\<title\>(.*)\<\/title\>/",$str,$data);
return $data[1];
}
}

echo getdata("http://www.w3schools.com/");

?>



Example URL : www.productsite.com


Product Web HTML Example :

<div class="products">
<a href="productsite.com" class="title"><strong>Product 1</strong></a><br/>
<p>http://www.productsite.com/simpleproducatpage1.aspx<br/></p>
<br/>
</div>
<div class="products">
<a href="productsite.com" class="title"><strong>Product 2</strong></a><br/>
<p>http://www.productsite.com/simpleproducatpage2.aspx<br/></p>
<br/>
</div>
<div class="products">
<a href="productsite.com" class="title"><strong>Product 3</strong></a><br/>
<p>http://www.productsite.com/simpleproducatpage3.aspx<br/></p>
<br/>
</div>
<div class="products">
<a href="productsite.com" class="title"><strong>Product 4</strong></a><br/>
<p>http://www.productsite.com/simpleproducatpage4.aspx<br/></p>
<br/>
</div>
<div class="products">
<a href="productsite.com" class="title"><strong>Product 5</strong></a><br/>
<p>http://www.productsite.com/simpleproducatpage5.aspx<br/></p>
<br/>
</div>
<div class="products">
<a href="productsite.com" class="title"><strong>Product 6</strong></a><br/>
<p>http://www.productsite.com/simpleproducatpage6.aspx<br/></p>
<br/>
</div>
<div class="products">
<a href="productsite.com" class="title"><strong>Product 7</strong></a><br/>
<p>http://www.productsite.com/simpleproducatpage7.aspx<br/></p>
<br/>
</div>
and so on ...

This Output i need :

http://www.productsite.com/simpleproducatpage1.aspx
http://www.productsite.com/simpleproducatpage2.aspx
http://www.productsite.com/simpleproducatpage3.aspx
http://www.productsite.com/simpleproducatpage4.aspx
http://www.productsite.com/simpleproducatpage5.aspx
http://www.productsite.com/simpleproducatpage6.aspx
http://www.productsite.com/simpleproducatpage7.aspx
and so on ...
mac34 is offline   Reply With Quote
Old 01-23-2013, 06:49 PM   PM User | #2
gvre
Regular Coder

 
Join Date: May 2011
Posts: 214
Thanks: 1
Thanked 50 Times in 49 Posts
gvre is an unknown quantity at this point
PHP Code:
$pattern '#<div class="products">.+?<p>(http://[^<]+)#si';
if (
preg_match_all($pattern$str$m))
{
        
$urls $m[1];

gvre is offline   Reply With Quote
Reply

Bookmarks

Tags
preg_match

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 06:31 AM.


Advertisement
Log in to turn off these ads.