Hello.

I've been through dozen of tutorials about regex, and obviously still don't understand everything.

I'm trying to get data (a whole DIV field and its contents) from another website, and display it on my page.

It seems to get everything, but the DIV field.

This is what I want: "<div id="s_1">CONTENT</div>"

How am I supposed to do it? This is the code so far:

<?php
$CurlStart = curl_init();
curl_setopt ($CurlStart, CURLOPT_URL, "http://www.supersport.hr/ponuda/client");
curl_setopt ($CurlStart, CURLOPT_HEADER, 0);
$source = curl_exec ($CurlStart);
curl_close ($CurlStart);

  $re1='.*?';
  $re2='<[^>]+>';
  $re3='(<[^>]+>)';
  $re4='((.*))';
  $re5='(<[^>]+>)';

  if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5."/is", $source, $matches))
  {
      print $matches;
  }

?>
Member Avatar for LastMitch

@Dino000

I'm trying to get data (a whole DIV field and its contents) from another website, and display it on my page.

It's not very helpful if you didn't provide a code or at least mention that you don't understand how it works. May I ask where is this <div> from the code you provided above?

<div id="s_1">CONTENT</div>"

Since you didn't mention anything about a div in your code. Then you can try this:

$str = '<div id="s_1">CONTENT</div>';

preg_match('/\<div id\=[\"]{0,1}content[\"]{0,1}\>(.*?)\<\/div\>/s', $content['content'], $str, $matches);
$content['content'] = $matches[1];
Member Avatar for diafol

WHy don't you just add it to the return value?

echo '<div id="whatever">' . $matches . '</div>';
commented: Nice Answer ! +0
Member Avatar for LastMitch

@Dino000

Just used diafol example it will save you a lot of time.

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.