Rectangle 27 0

file get contents php only retrieving one string from external div from url?


$activity = explode( '<div class="class">' , $content );
$activity_second = explode("</div>" , $activity );
<?php $url = "http://domain.com"; $content = file_get_contents($url);  preg_match_all('#<div class="class">(.+?)</div>#', $content, $matches);  echo $matches[1]; ?>
<div id="another-class"><div class="class">some text 1</div></div>
<div class="class">some text 2</div>
<div class="class">some text 3</div>
<div class="class">some text 4</div>
<div class="class">some text 5</div>
<div class="class">some text 6</div>
Array
(
    [0] => Array
        (
            [0] => <div class="class">some text 1</div>
            [1] => <div class="class">some text 2</div>
            [2] => <div class="class">some text 3</div>
            [3] => <div class="class">some text 4</div>
            [4] => <div class="class">some text 5</div>
            [5] => <div class="class">some text 6</div>
        )

    [1] => Array
        (
            [0] => some text 1
            [1] => some text 2
            [2] => some text 3
            [3] => some text 4
            [4] => some text 5
            [5] => some text 6
        )

)
preg_match_all('#<div class="class">(.+?)</div>#', $content, $matches);

$matches[1] is an array, so echoing it just like that won't work. For that you need a foreach statement, like this: foreach($matches[1] as $match) { echo $match; }

And you need the text contained the div elements. If this is correct, replace:

I did this and I'm getting the same as before just Array is being displayed on the website

In this example, after the function call $matches will have the following:

Let me see if I get it straight, you have something like this:

The data you need is in $matches[1].

You have got the concept correct though, that is what I am hoping to achieve

with this:

Note