Welcome Guest, Not a member yet? Register   Sign In
file_get_contents() and CI 3.0.0
#5

(06-12-2015, 07:06 AM)CroNiX Wrote: file_get_contents() only retrieves a file as a STRING. It doesn't "parse" or "execute" it. It's up to you what to do with the string. So after you retrieve a "page" using file_get_contents(), what are you trying to do with it? What are the contents of the file?

this is my parse function

PHP Code:
function parse($link)
 
   {
 
       $link    preg_match('/^https?:\/\//i'$link) ? $link 'http://'.$link;
 
       $url     parse_url($link);
 
       $url     $url['scheme'].'://'.$url['host'];
 
       $img_url $url;

 
       $link = @file_get_contents($link);

 
       $dom = new DOMDocument();
 
       @$dom->loadHTML($link);

 
       $link = new stdClass;
 
       $link->url $url;

 
       $titles $dom->getElementsByTagName('title');

 
       if ($titles)
 
       {
     
       $title $titles->item(0);
 
       }

 
       if (isset($title))
 
       {
     
       $link->title $title->nodeValue;
 
       }

 
       $meta $dom->getElementsByTagName('meta');

 
       if ($meta)
 
       {
 
           foreach ($meta as $elem)
 
           {
 
               if ($elem->getAttribute('property') == 'og:url')
 
               {
     
               $link->url $elem->getAttribute('content');
 
               }

 
               if ($elem->getAttribute('name') == 'description')
 
               {
     
               $link->description $elem->getAttribute('content');
 
               }

 
               if ($elem->getAttribute('property') == 'og:image')
 
               {
     
               $link->img $elem->getAttribute('content');
 
               }
 
           }
 
       }

 
       if ( ! isset($link->img))
 
       {
 
           $imgs $dom->getElementsByTagName('img');

 
           if ($imgs->length)
 
           {
     
           $img $imgs->item(rand(0$imgs->length 1))->getAttribute('src');
 
           }

 
           if (isset($img))
 
           {
     
           $link->img preg_match("/http/"$img) ? $img $img_url.$img;
 
           }
 
       }

 
       return $link;
 
   

this function works for the external pages but for the internal pages if only i am using 2.0, if i am using 3.0, it doesn't work
Reply


Messages In This Thread
file_get_contents() and CI 3.0.0 - by Tecvid - 06-12-2015, 04:22 AM
RE: file_get_contents() and CI 3.0.0 - by Tecvid - 06-12-2015, 05:39 AM
RE: file_get_contents() and CI 3.0.0 - by CroNiX - 06-12-2015, 07:06 AM
RE: file_get_contents() and CI 3.0.0 - by Tecvid - 06-12-2015, 07:39 AM
RE: file_get_contents() and CI 3.0.0 - by CroNiX - 06-12-2015, 12:21 PM
RE: file_get_contents() and CI 3.0.0 - by Tecvid - 06-12-2015, 09:08 PM
RE: file_get_contents() and CI 3.0.0 - by gadelat - 06-12-2015, 12:49 PM
RE: file_get_contents() and CI 3.0.0 - by Tecvid - 06-12-2015, 09:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB