Why is this 'include('wp-load.php')' with 'include('simple_html_dom.php')' will have

Why is this ‘include(‘wp-load.php’)’ with ‘include(‘simple_html_dom.php’)’ will have a conflict???

include ‘wp-load.php’ for run function wp_insert_post($post) ,
but once include ‘wp-load.php’ ,the parse function can not to run that in ‘simple_html_dom.php’.

//include(‘wp-load.php’); //include ‘wp-load.php’ for run function wp_insert_post($post)

$post = array();
$post[‘post_status’] = ‘publish’;
$post[‘post_author’] = 1;
$post[‘comment_status’] = ‘closed’;
$post[‘post_title’] = ‘’;
$post[‘post_content’] = ‘’;
$post[‘post_date’] = date(‘Y-m-d H:i:s’,strtotime(“now”));

$parseURL = ‘http://www.tradebit.com/visit.php/71080/product/-/87837706’;
$html = new simple_html_dom();
$title = $html->find(“title”, 0);
$title = explode(" - ", $title->plaintext);
$post[‘post_title’] = $title[0];
$post[‘post_content’] = $html->find(‘div[class=orangeContent]’,1);

echo '$post post_content ’ . $post[‘post_content’] . ‘<br>’;
echo ‘title’ . ‘<br>’;
echo $post[‘post_title’] . ‘<br>’;




We’d need to see what is in each include to be able to figure out the conflict.

hi felgall, thanks your reply.
when i enable include wp-load, simple html don cannot work, it throw error below.
Fatal error: Call to a member function find() on a non-object in C:\wamp\www\simple_html_dom.php on line 879

when i disable include wp-load, the simple html dom worked very well. but it throw error below:
Fatal error: Call to undefined function wp_insert_post() in C:\wamp\www\ estinclude.php on line 26

function wp_insert_post() cannot to work for it need wp-load.

‘wp-load.php’)’ with ‘include(‘simple_html_dom.php’)’ have a conflict.

can anyone give me a hand? thanks a lot.

I already replied on your original thread:

I have no idea why there is a conflict. I’ve never mixed Simple HTML DOM and WordPress before and I’m not surprised that a conflict arises. WP is a massive beast and it is inevitable that it will conflict with something. You have two options:

  1. Stop trying to drag in WP and just insert the post into the database via some other means.

  2. Move the web scraping part of the code into a separate file (e.g. ‘webscraper.php’) and use something like file_get_contents(“http://yourserver.com/path/to/webscraper.php”); to extract the content from the code that drags in WP.

I would personally do #1 just because I’m used to it. But #2 is probably “more correct” - albeit a lot slower.

@felgall - ‘wp-load.php’ is the main WordPress loader script. You can include it from within the web server environment and then have access to all of the primary WP functionality. Useful for running cron scripts for newbies to WP but chugs RAM like nothing else.

‘simple_html_dom.php’ is Simple HTML DOM. It makes parsing web scraped content super easy with its jQuery-like selector syntax. Infinitely better than trying to use preg_match(). I just got done making a web scraping toolkit that happens to include this library.