0

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!

4
Contributors
6
Replies
10
Views
6 Years
Discussion Span
Last Post by karlmarsh05
0

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!

0

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.

0

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.

Edited by calebcook: n/a

0

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

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!

0

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.

Edited by karlmarsh05: forgot important bit

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.