HI. I've tried other codes, but they don't seem to work. What I'm trying to do, is grab a result from google's shopping page, and display it on my page. I only want the title, which is in the tag:

<h3 class="result-title">TITLE</h3>

How do I do that in PHP?

Thanks!

Recommended Answers

All 6 Replies

I've tried

<?php
$data = 'aaa <div class="main">content</div> bbb';
preg_match_all ("/<div.*?>([^`]*?)<\/div>/", $data, $matches);

echo print_r($matches, true);
?>

That displays:

Array ( [0] => Array ( [0] =>
content
) [1] => Array ( [0] => content ) )

I want it to just display 'content'.

Can someone help me with this?

Thank you!

Member Avatar for diafol

Your posts make little sense. You want:

<h3 class="result-title">TITLE</h3>

But are using preg_match for divs??
Rephrase the question, be specific.

I had read a forum on the topic, and it said that I could change the preg_match to h3 to get it to work. I tried that, and it didn't work. So, I then tried it with div's, and that gave the result I gave above. I forgot to change it to h3 for this post. :)
Basically, if I can get either h3 or div, I'll be good.

I've tried

<?php
$data = 'aaa <div class="main">content</div> bbb';
preg_match_all ("/<div.*?>([^`]*?)<\/div>/", $data, $matches);

echo print_r($matches, true);
?>

That displays:

Array ( [0] => Array ( [0] =>
content
) [1] => Array ( [0] => content ) )

I want it to just display 'content'.

Can someone help me with this?

Thank you!

Then you need to loop the array, for display the content

$data = 'aaa <div class="main">content</div> bbb';
preg_match_all ("/<div.*?>([^`]*?)<\/div>/", $data, $matches);

$content = $matches[1];
$total = count($content);
for($i=0; $i<$total; $i++){
echo $content[$i]."<br />";
}

Then you need to loop the array, for display the content

$data = 'aaa <div class="main">content</div> bbb';
preg_match_all ("/<div.*?>([^`]*?)<\/div>/", $data, $matches);

$content = $matches[1];
$total = count($content);
for($i=0; $i<$total; $i++){
echo $content[$i]."<br />";
}

@leakbali: Thanks so much! The code works great!

Hi please help me :)

I am trying to basically echo the entire contents of a div located on an external file. The div contains text, images and links.

My existing method currently displays nothing when I execute the script. Why? I might add that when I inspect element in google chrome there is also nothing there (blank space), in the HTML or PHP file.

<?php

$file = "http://myworld.ebay.co.uk/digitalzoneonline";

$data = file_get_contents($file);

preg_match_all ("/<div id=\"Content\">([^`]*?)<\/div>/", $data, $listings);

$content = $listings[1];
$total = count($content);
for($i=0; $i<$total; $i++){
echo $content[$i]."";
}

?>

Please please help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.