0

I would like to know if it is possible to grab text from a website for example http://example.com

let's say there is paragraphs there

.............Hello234................................

So I want to grab the "Hello" text on my website http://mywebsite.com

so even if the hello changes I want to grab that.

thank you.

Ace
  • 1
  • 2
  • 1
    You need an anchor. For instance, a CSS selector, an XPath query, or something that can take you to the text you want to grab. – Thai May 09 '11 at 03:24
  • 1
    and permission of the website you are taking content from –  May 09 '11 at 03:28

1 Answers1

0

The 'get_file_contents' function will return the HTML of the url given.

$text = file_get_contents('http://www.example.com/');

You can then use regular expressions or other string manipulation tools to find the paragraph you need.

preg_match( '/<p id="blah">(.+)</p>/', $text, $matches );

It depends on what content you want to extract from the source.

Kane Wallmann
  • 2,292
  • 15
  • 10
  • nooooooooooooooooooooooooooo............. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – mpen May 09 '11 at 04:11
  • He never said he wanted to parse the HTML page and nor did I suggest that he does... – Kane Wallmann May 09 '11 at 04:25
  • what about extra spaces or line breaks between `p` and `id`? extra content after `"blah"`? No quotes? Single quotes? There's so many cases you didn't cover with that regex. Even to pull data from a single field, it's usually better to use a tool that can parse HTML and then you can easily query it. – mpen May 09 '11 at 15:58