JqueryUI slider does not work when parsing dom element

I am using a simple HTML parser. Everything works well with my code, but jqueryui does not work, and for some sites it does not display images. Please check live here and try using a simple HTML parser .

Enter the URL in the text box with the URL. You can see that the images are not loaded, and the sliders do not work. Here is my code

<?php include_once 'simple_html_dom.php'; $data = new simple_html_dom(); if ( isset($_REQUEST['url_name']) ) { if ( strpos($_REQUEST['url_name'], "http://") === false && strpos($_REQUEST['url_name'], "//") === false ) { $_REQUEST['url_name']="http://".$_REQUEST['url_name']; } $url_name = $_REQUEST['url_name']; if ( strpos($_REQUEST['url_name'], "/") === false ) { $url_name = $_REQUEST['url_name'].'/'; } // Load HTML from an URL $data->load_file($_REQUEST['url_name']); foreach ( $data->find('img') as $element ) { $element->target='_blank'; if ( strpos($element, ".com") === false && strpos($element, ".net") === false && strpos($element, ".org") === false && strpos($element, "http://") === false && strpos($element, "https://") === false ){ $element->src=$url_name.$element->src; } } foreach ( $data->find('style') as $element ) { if ( strpos($element, ".com") === false && strpos($element, ".net") === false && strpos($element, ".org") === false && strpos($element, "http://") === false && strpos($element, "https://") === false ){ $element->src=$url_name.$element->src; } } foreach ( $data->find('script') as $element ) { if ( strpos($element, ".com") === false && strpos($element, ".net") === false && strpos($element, ".org") === false && strpos($element, "http://") === false && strpos($element, "https://") === false ){ $element->src=$url_name.$element->src; } } foreach ( $data->find('link') as $element ) { if ( strpos($element, ".com") === false && strpos($element, ".net") === false && strpos($element, ".org") === false && strpos($element, "http://") === false && strpos($element, "https://") === false ){ $element->href=$url_name.$element->href; } } foreach ( $data->find('a') as $element ) { if ( strpos($element->href, ".com") === false && strpos($element->href, ".net") === false && strpos($element->href, ".org") === false && strpos($element->href, "http://") === false && strpos($element->href, "https://") === false ){ $element->href = "form_submit.php?url_name=".$url_name.$element->href; } else { $element->href = "form_submit.php?url_name=".$element->href; } } echo $newHtml; } ?> 
+5
source share
1 answer

What are you trying to do?

I just guessed that you need a list of all hosted img, css, js and URLs.

  • $newHtml has never been specified anywhere in your code.
  • What is your simple_html_dom class? I will take it as follows: http://simplehtmldom.sourceforge.net/
    • either, or you intended echo $data; in the end.
  • features! at least!

You need to find out the rest

Since I really don't know what you're going for, what your simple_html_dom , all I can do is introduce you to more advanced coding concepts.

  • Proper use of spaces to style code
    • some people will disagree with my choices here, but this will greatly improve readability.
  • If you have really long lines, expand them.
  • If you have blocks of almost identical code repeating throughout the code, this should probably be a function.
  • When debugging / troubleshooting, either an echo file or a debugger (xdebug).
  • Comment your code better that I should not teach you here why you should always.

Adjusted Code:

 <?php include_once 'simple_html_dom.php'; $data = new simple_html_dom(); if ( isset($_REQUEST['url_name']) ) { if ( strpos($_REQUEST['url_name'], "http://") === false && strpos($_REQUEST['url_name'], "//") === false ) { $_REQUEST['url_name']="http://".$_REQUEST['url_name']; } $data->my_url_name = $_REQUEST['url_name']; if ( strpos($_REQUEST['url_name'], "/") === false ) { $data->my_url_name = $_REQUEST['url_name'].'/'; } echo "<div style='border:1px solid blue;'>"; // Load HTML from an URL $data->load_file($_REQUEST['url_name']); modifyUrls($data, 'img', array('target' => '_blank')); modifyUrls($data, 'style'); modifyUrls($data, 'script'); modifyUrls($data, 'link', array(), 'href'); foreach ( $data->find('a') as $element ) { if ( checkurl($element->href) ) { echo $element->href = "form_submit.php?url_name=". $data->my_url_name . $element->href; } else { echo $element->href = "form_submit.php?url_name=". $element->href; } echo "<br>"; } echo "</div><div style='border:1px solid red;'>"; echo $data; echo "</div>"; } function modifyUrls(&$dataObj, $target, $options = array(), $urlAttribute = "src") { foreach ( $dataObj->find($target) as $element ) { if ( !empty($options) ) { foreach ($options as $field => $value) { $element->{$field} = $value; } } if ( checkurl($element) ) { echo $element->{$urlAttribute} = $dataObj->my_url_name . $element->{$urlAttribute}; echo "<br>"; } } } function checkurl($url){ if ( strpos($url, ".com") === false && strpos($url, ".net") === false && strpos($url, ".org") === false && strpos($url, "http://") === false && strpos($url, "https://") === false ){ return true; } return false; } 
0
source

Source: https://habr.com/ru/post/1238601/


All Articles