phoenixx Posted December 2, 2008 Share Posted December 2, 2008 I am simply trying to extract the href and title from the following syntax: <div class="prod_image"> <a title="Diamond Plate Diamond Plate™ Rock Design Ladies' Genuine Leather Motorcycle Jacket" href="/catalog/search/search_hit.php?product_id=36775&location=/catalog/36775.html"> I've tried the following but receiving an error: preg_match_all('/<div class="prod_image".*?a title="([^"]*)".*?href=".*?href="([^"]*)">/is',$data,$out); $d = array_combine($out[1], $out[2]); foreach($d as $k=>$v){ echo "" . $k . $v . "<br>"; Link to comment https://forums.phpfreaks.com/topic/135165-solved-simple-extract-url-and-title-tag-question/ Share on other sites More sharing options...
rhodesa Posted December 2, 2008 Share Posted December 2, 2008 you have href twice: preg_match_all('/<div class="prod_image".*?a title="([^"]*)".*?href="([^"]*)">/is',$data,$out); also...not sure if you can use those titles as array keys...try this code instead: preg_match_all('/<div class="prod_image".*?a title="([^"]*)".*?href=".*?href="([^"]*)">/is',$data,$out); foreach(array_keys($out) as $n){ $title = $out[1][$n]; $href = $out[2][$n]; echo "$title: $href<br>"; } Link to comment https://forums.phpfreaks.com/topic/135165-solved-simple-extract-url-and-title-tag-question/#findComment-703982 Share on other sites More sharing options...
phoenixx Posted December 2, 2008 Author Share Posted December 2, 2008 The code eliminated the error but produces no output. Link to comment https://forums.phpfreaks.com/topic/135165-solved-simple-extract-url-and-title-tag-question/#findComment-704059 Share on other sites More sharing options...
rhodesa Posted December 2, 2008 Share Posted December 2, 2008 <?php preg_match_all('/<div class="prod_image".*?a title="([^"]*)".*?href="([^"]*)">/is',$data,$out); foreach(array_keys($out[0]) as $n){ $title = $out[1][$n]; $href = $out[2][$n]; echo "$title: $href<br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/135165-solved-simple-extract-url-and-title-tag-question/#findComment-704110 Share on other sites More sharing options...
phoenixx Posted December 2, 2008 Author Share Posted December 2, 2008 PERFECT! Many thanks! Link to comment https://forums.phpfreaks.com/topic/135165-solved-simple-extract-url-and-title-tag-question/#findComment-704133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.