Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
help with function get
Old 04-27-2010, 05:47 PM help with function get
ZoC
Skilled Talker

Posts: 68
Trades: 0
hello there, im working to one script and i dont understand why is not working ... hope someone can tell me the problem

Code:
 $link = 'http://www.google.com';
if my function get code is

Code:
 function getWebPage($link) {
  $lines = @file($link);
  $str=implode("\n",$lines);
  preg_match('/<title>(.*?)<\/title>/', $str, $matches);
  if ( isset($matches['0']) ) {
   $title  = str_replace('<title>', '', $matches['0']);
   $title  = str_replace('</title>', '', $title);
   return $title;
  }
 }
is working is show me the title but i want to take all that page so i add the code like this

Code:
 function getWebPage($link) {
  $lines = @file($link);
  $str=implode("\n",$lines);
  preg_match('/<html>(.*?)<\/html>/', $str, $matches);
  if ( isset($matches['0']) ) {
   $title  = str_replace('<html>', '', $matches['0']);
   $title  = str_replace('</html>', '', $title);
   return $title;
  }
 }
but is not working like this and i dont want to use iframe ... can someone tell me what i mistake ? thanks again for all your help
ZoC is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-27-2010, 05:53 PM Re: help with function get
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
And you are trying to do what exactly??
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-27-2010, 06:50 PM Re: help with function get
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
1. Your function isn't working on http://google.com because the content of that site does not end in </html>

2. You are going in circles. You use file() to get the entire content of a site, then you use that regular expression to match everything between <html> tags, which should be the entire content of the site. Just use file_get_contents and then remove the html tags.

I wrote a more general form of the function you posted that can be used to extract content between any tag:
PHP Code:
function getContent($link$tag) {
    
$str file_get_contents($link);
    
preg_match('/<'$tag .'\b[^>]*>.*?<\/'$tag .'>/si'$str$matches);
    if ( isset(
$matches['0']) ) {
        
$content  preg_replace('/<'$tag .'\b[^>]*>/i'''$matches['0']);
        
$content  preg_replace('/<\/'$tag .'>/i'''$content);
        return 
$content;
    }

Ex:
PHP Code:
echo getContent('http://webmaster-talk.com''title'); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 04-27-2010 at 07:10 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-27-2010, 07:32 PM Re: help with function get
ZoC
Skilled Talker

Posts: 68
Trades: 0
thanks to all but after more search on google i find how i can make all this thanks again for your support ! best forum ever !

anyway this is my code if i can help someone who need this is easy ...

Code:
<?php 

 $uri = $_SERVER['REQUEST_URI'];
 $uri = str_replace('/google.php', '', $uri);

 $homepage = file_get_contents('http://www.google.com/'.$uri);

 $homepage = str_replace('Google', 'YourWebsiteName', $homepage);

 echo $homepage;

?>
and with little more work you can make your web search

Last edited by ZoC; 04-27-2010 at 07:34 PM..
ZoC is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to help with function get
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13505 seconds with 12 queries