2018-11-27 23:12
采纳率: 0%
浏览 41

Wordpress simple_html_dom.php管理页面

I've made as script using file_get_html. I'm now transfering it to a Wordpress site, and it doesn't seem to work.

Just trying to use it in a admin plugin.

Snippet below:

if (isset($_POST['submit_updateColors'])) {
        $qGetBrands = $mysqli->query("SELECT ... ");
        while ($rowBrands = $qGetBrands->fetch_assoc()) {

            $brandId = $rowBrands['cl_brand_Id'];
            $url =  "". $rowBrands['cl_brand_url'];
            $html = file_get_html($url);

            foreach($html->find('div[class=col-md-1p5]') as $brandColors) {
                foreach ($brandColors->find('h3') as $brandColor) {
                    $p_brandColor = $brandColor->innertext;

                foreach ($brandColors->find('img') as $ColorImg) {
                    $p_ColorImg = $ColorImg->src;
                    echo $p_brandColor ." <br />";
                    echo $imgName['basename'] ." <br /> <br />";

After while have started: echo "I'm here!!!" Results: "I'm here!!!"

After first foreach: echo "I'm here!!!" Results: Nothing

After $html = file_get_html($url);: echo "Result: ".$html; Results: Nothing, not even showing "Result"

Error messages:

Fatal error: Uncaught Error: Call to a member function find() on boolean in /home/xxx/public_html/wp-content/plugins/Farbkarte/index.php:67 Stack trace: #0 /home/xxx/public_html/wp-includes/class-wp-hook.php(286): main_init('') #1 /home/xxx/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #2 /home/xxx/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /home/xxx/public_html/wp-admin/admin.php(224): do_action('toplevel_page_f...') #4 {main} thrown in /home/xxx/public_html/wp-content/plugins/Farbkarte/index.php on line 67

I have no idea how to proceed, and would love to get some help! Outside wordpress, it works perfectly.

I hope I havent removed too much informaton.

Thanks in advance!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doupeng6890 2018-11-28 11:57

    I was able to solve this by looking at file_get_contents(): stream does not support seeking / When was PHP behavior about this changed?

    On line 75 of simple_html_dom.php:

    $contents = file_get_contents($url, $use_include_path, $context, $offset); I removed the reference to $offset:

    $contents = file_get_contents($url, $use_include_path, $context); No my page works fine. Not taking liability for anything else it breaks! :)

    解决 无用
    打赏 举报

相关推荐 更多相似问题