Jump to content

[SOLVED] Simple extract URL and Title Tag Question


phoenixx

Recommended Posts

I am simply trying to extract the href and title from the following syntax:

 

<div class="prod_image">						<a title="Diamond Plate Diamond Plate&trade; Rock Design Ladies&apos; 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>";

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>";
}

<?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>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.