Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can try my class It uses <strong>simple xml</strong></p> <p>Here's Code</p> <pre><code>&lt;?php class xml_grabber { private $xml_file = '' ; private $xml_link = '' ; private $xml_dom = '' ; private $xml_type = '' ; private $xml_content = '' ; private $xml_errors = array() ; public $xml_stack = 0 ; public $only_text = 0 ; private $xml_connect_count = 0 ; public function __construct($link_file_com = '') { if(!$link_file_com) { $this-&gt;xml_errors['construct'] = 'No Xml In Construct' ; return false; } elseif(!function_exists('simplexml_load_file') || !function_exists('simplexml_load_string') || !function_exists('simplexml_import_dom')) { $this-&gt;xml_errors['functions'] = 'simple xml function not exists' ; return false; } else { $this-&gt;set_xml(trim($link_file_com)) ; } } public function only_text( $val = 0 ) { $this-&gt;only_text = $val ; } public function set_xml($xml) { if(isset($xml{3})) { if(file_exists($xml)) { $this-&gt;xml_type = 1 ; $this-&gt;xml_file = $xml ; } elseif(filter_var($xml, FILTER_VALIDATE_URL)) { $this-&gt;xml_type = 2 ; $this-&gt;xml_link = $xml ; } else { $this-&gt;xml_type = 3 ; $this-&gt;xml_dom = $xml ; } } else { $this-&gt;xml_type = '' ; } } public function get_xml() { if($this-&gt;xml_type == '') { return false ; } elseif($this-&gt;xml_type == 1) { return $this-&gt;xml_file ; } elseif($this-&gt;xml_type == 2) { return $this-&gt;xml_link ; } elseif($this-&gt;xml_type == 3) { return $this-&gt;xml_dom ; } } public function set_columns($new_columns= array()) { return $this-&gt;xml_columns = $new_columns ; } public function get_columns() { return $this-&gt;xml_columns ; } public function load() { if($this-&gt;xml_type == '') { $this-&gt;xml_errors['loader'] = 'Unknown XML type' ; return false; } elseif($this-&gt;xml_type == 1) { $xml = simplexml_load_file($this-&gt;xml_file,null, LIBXML_NOCDATA) ; $this-&gt;xml_content = $xml ; } elseif($this-&gt;xml_type == 2) { $con = $this-&gt;connect($this-&gt;xml_link); $this-&gt;xml_content = simplexml_load_string(trim($con),null, LIBXML_NOCDATA) ; } elseif($this-&gt;xml_type == 3) { return $this-&gt;xml_dom ; } } public function fetch($return = 'array') { $xml = array() ; if($this-&gt;xml_content) { print_r ( $this-&gt;get_attribute($this-&gt;xml_content)) ; } } public function get_attribute($object) { if( (is_array( $object ) || is_object( $object )) &amp;&amp; count( $object ) &gt; 0 ) { foreach( $object as $k =&gt; $val ) { $count = count( $val ) ; $cou = count( $object-&gt;$k ) ; if( $count &gt; 0 and is_array( $val ) || is_object( $val ) ) { if( $cou &gt; 1 ) { $result['item'][] = $this-&gt;get_attribute( $val ) ; } else { $result[$k] = $this-&gt;get_attribute( $val ) ; } } else { $attr = $val-&gt;attributes() ; if( count( $attr ) &gt; 0 ) { $var ; foreach( $attr as $kk =&gt; $vv ) { $var[$kk] = (string) $vv ; } if( $cou &gt; 1 ) { $result[$k][] = $var ; } else { $result[$k] = $var ; } } else { $result[$k] = (string) $val ; } } } } else { $result[] = $object ; } return $result ; } /* public function fetch($return = 'array') { if($this-&gt;xml_content) { $rss_feed = $this-&gt;xml_content ; $rss_title = (string) $rss_feed-&gt;channel-&gt;title ; $rss_link = (string) $rss_feed-&gt;channel-&gt;link ; $rss_cat = (string) $rss_feed-&gt;channel-&gt;category ; $rss_image = (string) $rss_feed-&gt;channel-&gt;image-&gt;url ; $rss_summary = array ( 'info' =&gt; array( 'title'=&gt;$rss_title , 'link'=&gt;$rss_link , 'cat'=&gt;$rss_cat , 'image'=&gt;$rss_image ) , 'item' =&gt; array() ) ; if(is_array($rss_feed-&gt;channel) or is_object($rss_feed-&gt;channel)) { if(is_array($rss_feed-&gt;channel-&gt;item) or is_object($rss_feed-&gt;channel-&gt;item)) { foreach($rss_feed-&gt;channel-&gt;item as $item) { if($item-&gt;enclosure &amp;&amp; $item-&gt;enclosure-&gt;attributes()) { $image0 = $item-&gt;enclosure-&gt;attributes() ; $image_url = $image0 ['url'] ; } $result = array() ; foreach($item as $k=&gt;$v) { $result[strtolower($k)] = strip_tags((string) $v) ; } if(isset($image_url{1})) { $result['image0'] = $image_url ; } $rss_summary['item'][] = $result ; } } elseif(is_array($rss_feed-&gt;channel-&gt;entry) or is_object($rss_feed-&gt;channel-&gt;entry)) { foreach($rss_feed-&gt;channel-&gt;entry as $item) { if($item-&gt;enclosure &amp;&amp; $item-&gt;enclosure-&gt;attributes()) { $image0 = $item-&gt;enclosure-&gt;attributes() ; $image_url = $image0 ['url'] ; } $result = array() ; foreach($item as $k=&gt;$v) { $result[strtolower($k)] = (string) $v ; } if(isset($image_url{1})) { $result['image0'] = $image_url ; } $rss_summary['item'][] = $result ; } } } else { if(is_array($rss_feed-&gt;item) or is_object($rss_feed-&gt;item)) { foreach($rss_feed-&gt;item as $item) { if($item-&gt;enclosure &amp;&amp; $item-&gt;enclosure-&gt;attributes()) { $image0 = $item-&gt;enclosure-&gt;attributes() ; $image_url = $image0 ['url'] ; } $result = array() ; foreach($item as $k=&gt;$v) { $result[strtolower($k)] = (string) $v ; } if(isset($image_url{1})) { $result['image0'] = $image_url ; } $rss_summary['item'][] = $result ; } } elseif(is_array($rss_feed-&gt;entry) or is_object($rss_feed-&gt;entry)) { foreach($rss_feed-&gt;entry as $item) { if($item-&gt;enclosure &amp;&amp; $item-&gt;enclosure-&gt;attributes()) { $image0 = $item-&gt;enclosure-&gt;attributes() ; $image_url = $image0 ['url'] ; } $result = array() ; foreach($item as $k=&gt;$v) { $result[strtolower($k)] = (string) $v ; } if(isset($image_url{1})) { $result['image0'] = $image_url ; } $rss_summary['item'][] = $result ; } } } if($return == 'json') { return json_encode($rss_summary) ; } elseif($return == 'serialize') { return serialize($rss_summary) ; } elseif($return == 'xml') { return xml_encode($rss_summary) ; } else { return $rss_summary ; } } else { $this-&gt;xml_errors['fetch'] = 'No Xml Content' ; } } */ protected function connect($link,$post='') { if(!filter_var($link, FILTER_VALIDATE_URL)) { $this-&gt;xml_errors['connect'] = 'Not Vaild Link To Get data' ; return false ; } if(function_exists('curl_init')) { $cu = curl_init(); curl_setopt($cu,CURLOPT_URL,$link); curl_setopt($cu,CURLOPT_AUTOREFERER,true); if($post != '') { curl_setopt($cu,CURLOPT_HEADER, 1); curl_setopt($cu,CURLOPT_POST,3); curl_setopt($cu,CURLOPT_POSTFIELDS,$post); } curl_setopt($cu,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']); curl_setopt($cu,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($cu,CURLOPT_SSL_VERIFYHOST,false); curl_setopt($cu,CURLOPT_RETURNTRANSFER,true); $co = curl_exec($cu) ; if($co) { $con = $co ; } else { $this-&gt;xml_errors['connect'] = 'No Result From Curl' ; $this-&gt;xml_errors['curl'] = curl_error($cu); } curl_close($cu) ; } if(!$con and function_exists('ini_get')) { $url_fopen = ini_get('allow_url_fopen') ; if($url_fopen == 0) { if(function_exists('ini_set')) { ini_set('allow_url_fopen', 1) ; } $check_fopen = 1 ; } else { $check_fopen = 0 ; } if($check_fopen == 1) { $url_fopen = ini_get('allow_url_fopen') ; } if($url_fopen == 1) { if(function_exists('file_get_contents') and !$con) { $con = @file_get_contents($link) ; if($con) { $con ; } else { $this-&gt;xml_errors['connect'] = 'No Result From file_get_contents' ; } } elseif(function_exists('readfile') and !$con) { $con = @readfile($link); if($con) { $con ; } else { $this-&gt;xml_errors['connect'] = 'No Result From readfile' ; } } elseif(function_exists('file') and !$con) { $con = @file($link) ; if($con) { $con ; } else { $this-&gt;xml_errors['connect'] = 'No Result From file' ; } } } } if(!$con) { $this-&gt;xml_errors['connect'] = 'Curl And Allow Url Fopen Disabled On Server' ; return false ; } elseif(stripos($con,'DDoS protection by CloudFlare') and $this-&gt;xml_connect_count &lt; 1) { echo '&lt;h2&gt; Curl Answer No : '.$this-&gt;xml_connect_count.' &lt;/h2&gt;'.$con.'&lt;br /&gt;'; preg_match('/'.preg_quote('.val(').'(.*?)'.preg_quote(');').'/is', $con, $match); $matc = str_replace('+', " + ", $match[1]) ; $matc = str_replace('*', " * ", $matc) ; $post = eval ("return $matc ;") ; $html=new DOMDocument(); $html-&gt;loadHTML($con) ; $xpath = new DOMXPath($html); $tags = $xpath-&gt;query('//input[@type="hidden"]'); $fields = array(); foreach ($tags as $tag) { $fields[trim($tag-&gt;getAttribute('name'))] = trim($tag-&gt;getAttribute('value')) ; } $post_data = 'act=jschl&amp;jschl_vc='.$fields['jschl_vc'].'&amp;jschl_answer='.$post ; echo '&lt;h2&gt; I will post this info to curl &lt;/h2&gt;'.$post_data.'&lt;br /&gt; ' ; $this-&gt;xml_connect_count = $this-&gt;xml_connect_count + 1 ; sleep(5) ; $con = $this-&gt;connect($link , $post_data) ; echo '&lt;h2&gt; Curl Answer No : 1 &lt;/h2&gt;'. $con.'&lt;br /&gt;' ; preg_match('/^Set-Cookie: (.*?);/m', $con, $m); echo '&lt;h2&gt; Cookie from Result &lt;/h2&gt;' ;var_dump(parse_url($m[1])); } else { return $con ; } } public function get_error() { return $this-&gt;xml_errors ; } } ?&gt; </code></pre> <p>Here's How to use it</p> <pre><code>&lt;?php $rss = new xml_grabber('xml.xml') ; $rss -&gt; load() ; $x = $rss -&gt; fetch() ; print_r ( $x ) ; ?&gt; </code></pre> <p>Example</p> <pre><code>&lt;?xml version="1.0" encoding="Windows-1256"?&gt; &lt;rss version="2.0"&gt; &lt;channel&gt; &lt;info name="xml_reader" vesrion="1.0" author="sec.php"&gt;&lt;/info&gt; &lt;title&gt; Xml By sec.php &lt;/title&gt; &lt;company&gt; &lt;name&gt;Test Co&lt;/name&gt; &lt;link href="link1" rel="self"/&gt; &lt;link href="link2" rel="www"/&gt; &lt;/company&gt; &lt;company&gt; &lt;name&gt;Test Co&lt;/name&gt; &lt;link href="link1" rel="self"/&gt; &lt;link href="link2" rel="www"/&gt; &lt;/company&gt; &lt;company&gt; &lt;name&gt;Test Co&lt;/name&gt; &lt;link href="link1" rel="self"/&gt; &lt;link href="link2" rel="www"/&gt; &lt;/company&gt; &lt;/channel&gt; &lt;/rss&gt; </code></pre> <p>Result Array ( [channel] => Array ( [info] => Array ( [name] => xml_reader [vesrion] => 1.0 [author] => sec.php )</p> <pre><code> [title] =&gt; Xml By sec.php [item] =&gt; Array ( [0] =&gt; Array ( [name] =&gt; Test Co [link] =&gt; Array ( [0] =&gt; Array ( [href] =&gt; link1 [rel] =&gt; self ) [1] =&gt; Array ( [href] =&gt; link2 [rel] =&gt; www ) ) ) [1] =&gt; Array ( [name] =&gt; Test Co [link] =&gt; Array ( [0] =&gt; Array ( [href] =&gt; link1 [rel] =&gt; self ) [1] =&gt; Array ( [href] =&gt; link2 [rel] =&gt; www ) ) ) [2] =&gt; Array ( [name] =&gt; Test Co [link] =&gt; Array ( [0] =&gt; Array ( [href] =&gt; link1 [rel] =&gt; self ) [1] =&gt; Array ( [href] =&gt; link2 [rel] =&gt; www ) ) ) ) ) </code></pre> <p>)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload