0

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

?>

Edited by Dino000

3
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by LastMitch
0

@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];

Edited by LastMitch: grammer

1

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

echo '<div id="whatever">' . $matches . '</div>';
Votes + Comments
Nice Answer !
0

@Dino000

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

This topic has been dead for over six months. 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.