php - How do I display content grabbed from external websites?

Solution:
I would not recommend regex for parsing HTML. PHP 5+ comes with a parser which you can use as shown below.
$content = file_get_contents('test.html');
$doc =
<<<DOC
$content
DOC;
$dom = new DOMDocument();
$dom->loadHTML($doc);
$h2Tags = $dom->getElementsByTagName("h2");
$pTags = $dom->getElementsByTagName("p");
foreach($h2Tags as $h2 ) {
//do something
}
foreach($pTags as $p ) {
if($p->getAttribute("class") == "date") {
//do something
}
}
$h2 is of type DOMElement. It inherits DOMNode. So you can use nodeValue property to access the values. In the above example, you can write $h2->nodeValue to access the content.
Answer
Solution:
you can try this library http://simplehtmldom.sourceforge.net/
then just:
foreach($dom->find('p[class=date]' as $p) {
$date = $p->innertext;
}
this would give you the contents of
or you do it more globaly and dig through with stripos
foreach($dom->find('p') as $p) {
if(stripos($p->class, 'date') !== false) {
//do something
}
}
Answer
Solution:
Here's an example for using cURL:
http://tr2.php.net/manual/en/curl.examples-basic.php
and check if you are getting data before applyingpreg_match
. If you get some, then it's the regex which causes your problem.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: your system folder path does not appear to be set correctly. please open the following file and correct this: index.php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.