Is it possible to read data from other website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vinoth
Forum Contributor
Posts: 113
Joined: Thu Aug 02, 2007 3:08 am
Location: India
Contact:

Is it possible to read data from other website

Post by vinoth »

Hi all.

Is it possible to read the contents from website and insert the data to our DB.
I think it was possible to read data and insert to our DB.

If anybody did this, please instruct me to how to fix that.

Provide some solutions, logics or some code to fix this issue.
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Re: Is it possible to read data from other website

Post by mchaggis »

Try reading the following:
http://www.php.net/manual/en/function.fopen.php

You can read webpages just like you can read text files.

Or for more control, try:

http://www.php.net/manual/en/book.curl.php
vinoth
Forum Contributor
Posts: 113
Joined: Thu Aug 02, 2007 3:08 am
Location: India
Contact:

Re: Is it possible to read data from other website

Post by vinoth »

Thanks mchaggis.

I am open the file using Fopen & read the contents Its working fine

By using strpos I will move to the particular position, Is it any way to get the character present on the previous 2 position.
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Re: Is it possible to read data from other website

Post by mchaggis »

Hi vinoth,

Without seeing you code I am not too sure what you are after doing. If you are searching for a string and then want the previous character 2characters before the found string, you probably just need to use substr:

Code: Select all

 
<?php
if ( ($position = strpos( $data, 'string )) ) {
        $char = substr($data, ($position-2),1);
}
 
vinoth
Forum Contributor
Posts: 113
Joined: Thu Aug 02, 2007 3:08 am
Location: India
Contact:

Re: Is it possible to read data from other website

Post by vinoth »

Hi mchaggis,

I am also used strpos() to find the particular text is present or not?

if(strpos() == false){
No action;
}else{
substr() function to cut the records from the string;
}

It was Working fine..
I am not sure, Is it sufficient or any or other better solutions ?

Please guide me, If any other possibilities available otherwise I kept the same as it was working currently.
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Re: Is it possible to read data from other website

Post by mchaggis »

vinoth wrote:Hi mchaggis,

I am also used strpos() to find the particular text is present or not?

if(strpos() == false){
No action;
}else{
substr() function to cut the records from the string;
}
I usually sty the function strstr to see if a string is within another string, however, for your code above, try the following:

Code: Select all

<?php
if ( ($position = strpos( $data, 'string' )) ) {
    $char = substr($data, ($position-2),1);
}
?>
vinoth
Forum Contributor
Posts: 113
Joined: Thu Aug 02, 2007 3:08 am
Location: India
Contact:

Re: Is it possible to read data from other website[RESOLVED]

Post by vinoth »

Hi mchaggis,

Thanks for the suggestions & code you provided.
Its working Fine
Post Reply