Jump to content

preg_match_all help


skwap

Recommended Posts

hello friends,

 

i want to copy entire data from a website using preg_match_all function. But many times i tried iam getting only blank arrays

 

 

Website code :

<div class="pad">
							<a class='thumb' href='http://www.sitename.com/I-m-Sorry-To-Say-But-That-s-What-Miley-Was-Really-Screaming-187/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/187.jpg'>
				<div class='thumbtitle'>I'm Sorry To Say But That's Wh</div>
				<div class='views'>6960 views</div>
				</a><a class='thumb' href='http://www.sitename.com/Girl-s-Face-209/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/209.jpg'>
				<div class='thumbtitle'>Girls face - On a date vs In r</div>
				<div class='views'>6592 views</div>
				</a><a class='thumb' href='http://www.sitename.com/How-Men-And-Women-React-To-A-Surprise-Squirrel-On-The-Road-149/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/149.jpg'>
				<div class='thumbtitle'>How Men And Women React To A S</div>
				<div class='views'>3671 views</div>
				</a><a class='thumb' href='http://www.sitename.com/Easier-Than-I-Thought-31/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/31.jpg'>
				<div class='thumbtitle'>Easier Than I Thought</div>
				<div class='views'>3579 views</div>
				</a><a class='thumb' href='http://www.sitename.com/How-To-Dodge-A-Kick-29/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/29.jpg'>
				<div class='thumbtitle'>How To Dodge A Kick</div>
				<div class='views'>3105 views</div>
				</a><a class='thumb' href='http://www.sitename.com/GAHHWD-DAYUM-658/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/658.jpg'>
				<div class='thumbtitle'>GAHHWD DAYUM!</div>
				<div class='views'>3079 views</div>
				</a><a class='thumb' href='http://www.sitename.com/White-Girls-Be-Acting-Like-This-In-The-Club-248/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/248.jpg'>
				<div class='thumbtitle'>White Girls Be Acting Like Thi</div>
				<div class='views'>2984 views</div>
				</a><a class='thumb' href='http://www.sitename.com/How-To-Wake-Up-Like-A-Gangsta-DMX-Approved-214/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/214.jpg'>
				<div class='thumbtitle'>How To Wake Up Like A Gangsta(</div>
				<div class='views'>2969 views</div>
				</a><a class='thumb' href='http://www.sitename.com/Alien-Abduction-210/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/210.jpg'>
				<div class='thumbtitle'>Alien Abduction!</div>
				<div class='views'>2935 views</div>
				</a><a class='thumb' href='http://www.sitename.com/My-Humps-125/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/125.jpg'>
				<div class='thumbtitle'>My Humps</div>
				<div class='views'>2828 views</div>
				</a><a class='thumb' href='http://www.sitename.com/Reasons-Not-To-Date-Online-86/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/86.jpg'>
				<div class='thumbtitle'>Reasons Not To Date Online</div>
				<div class='views'>2827 views</div>
				</a><a class='thumb' href='http://www.sitename.com/White-People-VS-Black-People-Reaction-To-Magic-128/order/popular'>
				<img src='http://www.sitename.com/pictures/tb/128.jpg'>
				<div class='thumbtitle'>White People VS Black People R</div>
				<div class='views'>2816 views</div>
				</a><div class="clear"></div>

PHP Code i used :

<?php



$data = file_get_contents("http://www.sitename.com/tag/Funny/order/top/page/1");

$sPattern = '~<div class=\"pad\"><a class=\'thumb\' href=\'(.*)\'><img src=\'(.*)\'><div class=\'thumbtitle\'>(.*)</div></a><div class="clear"></div><div id="pagination">~Ui';

preg_match_all($sPattern,$data,$aMatch);


			
print_r($aMatch);




?>

Output iam getting :

Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) [3] => Array ( ) )

I need to get the stared (****) values from the html content of all items

 

<a class='thumb' href='*****'>
                <img src='*****'>
                <div class='thumbtitle'>******</div>
                </a><a class='thumb' href='****'>

 

 

 

Thanks In advance

 

 

Link to comment
Share on other sites

Does anything get output when you do the var_dump? I can see from the character count that it's long, so I wouldn't be surprised if the output is truncated, but I would still expected to see a little bit..

 

Try print_r, or echo of the $data variable. Then you can use a regex tester like this, http://www.solmetra.com/scripts/regex/, to test your pattern against the data you're trying to match against.

Looking at your pattern, that would be the opening div and a tag.

 

Basically you're just trying to get your pattern right, so using the regex tester will help you with that.

 

Denno

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.