Page 1 of 1

Is it possible to read data from other website

Posted: Wed May 07, 2008 7:36 am
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.

Re: Is it possible to read data from other website

Posted: Wed May 07, 2008 9:00 am
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

Re: Is it possible to read data from other website

Posted: Thu May 08, 2008 1:50 am
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.

Re: Is it possible to read data from other website

Posted: Thu May 08, 2008 3:08 am
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);
}
 

Re: Is it possible to read data from other website

Posted: Mon May 12, 2008 12:49 am
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.

Re: Is it possible to read data from other website

Posted: Mon May 12, 2008 3:25 am
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);
}
?>

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

Posted: Mon May 12, 2008 8:26 am
by vinoth
Hi mchaggis,

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