Jump to content

[SOLVED] Simple extract URL and Title Tag Question


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

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.