skwap Posted August 18, 2013 Share Posted August 18, 2013 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 https://forums.phpfreaks.com/topic/281292-preg_match_all-help/ Share on other sites More sharing options...
denno020 Posted August 18, 2013 Share Posted August 18, 2013 do a var_dump of the $data variable to check what the data actually is, there might be other characters in there that you didn't expect. Link to comment https://forums.phpfreaks.com/topic/281292-preg_match_all-help/#findComment-1445591 Share on other sites More sharing options...
skwap Posted August 18, 2013 Author Share Posted August 18, 2013 After using var_dump($data) Output : string(8337) " Link to comment https://forums.phpfreaks.com/topic/281292-preg_match_all-help/#findComment-1445595 Share on other sites More sharing options...
denno020 Posted August 18, 2013 Share Posted August 18, 2013 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 https://forums.phpfreaks.com/topic/281292-preg_match_all-help/#findComment-1445601 Share on other sites More sharing options...
skwap Posted August 18, 2013 Author Share Posted August 18, 2013 when iam echo $data iam getting the entire site with html contents Link to comment https://forums.phpfreaks.com/topic/281292-preg_match_all-help/#findComment-1445603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.