Page 1 of 2

Modify data brought in via <?php include

Posted: Thu Jan 15, 2009 4:01 pm
by drfb
:banghead: I have been browsing so many different sites/forums and can not find the answer.
It is so hard to think of how i should be typing questions etc into search engines..
None of them have brought out any results that have helped..

I was wondering about the following:

I am going to be using <?php Include to import info from an external site (with thier permission)..
The company doesn't mind me doing this however they will not adjust any settings to make my life easier.

I would like to know if i am able to <?php include and with some extra php coding in my site, be able to
change the img src tags to point to the original site.. Currently when i do the include it shows the foldername/image.gif
But i want it to grab the file from the original site and not try to access my server..
For Example:
CURRENT FORMAT -- img src="images/foldername/image.gif"
PREFERRED FORMAT -- img src="http://www.sitename.com/images/foldername/image.gif"

Is it at all possible to somehow do this all within some php coding in 1 file?

Re: Modify data brought in via <?php include

Posted: Thu Jan 15, 2009 4:06 pm
by alex.barylski
If the server won't do anything to make your life easier than you SOL.

You can "technically" include files on a remote server:

Code: Select all

<?php include 'ftp://domain:user@pass/somefile.inc.php'; ?>
FTP syntax is probably wrong -- that was off the top of my head

The problem is, you would need FTP access and a PHP setup that allowed URL's in your path.

If you do not have FTP access you can only include publically accessible files, so if they have a 'includes' directory which is in the document root and not password protected, you could do something like:

Code: Select all

$buff = file_get_contents('http://somedomain.com/includes/header.html')
You will NOT have access to their original PHP source code though...this is impossible without FTP access and it doesn't sound like they have give that to you.

Not sure what it is your doing, but if your doing what I think your trying to do, your in for a LOT of work.

Cheers,
Alex

Re: Modify data brought in via <?php include

Posted: Thu Jan 15, 2009 4:46 pm
by kipp
There isn't a way he could do a find and replace type action to the imported data prior to displaying in browser?

Re: Modify data brought in via <?php include

Posted: Fri Jan 16, 2009 7:13 am
by drfb
kipp wrote:There isn't a way he could do a find and replace type action to the imported data prior to displaying in browser?
Thanks for your replies so far..
I know i wrote a big post as my intial request for info, but in a round about way 'Kipp' that is what i would like to
do if possible..

Possibly include the file into my php then do a find/replace action of the imported data, once it is replaced
it will then display..

Could this be possible? :?:

Re: Modify data brought in via <?php include

Posted: Fri Jan 16, 2009 9:08 am
by mattpointblank
The search and replace is fine and straightforward, but as PCSpectra says, actually including the file will be tough / impossible. Do they have an RSS feed you could use, maybe?

Re: Modify data brought in via <?php include

Posted: Fri Jan 16, 2009 9:17 am
by drfb
mattpointblank wrote:The search and replace is fine and straightforward, but as PCSpectra says, actually including the file will be tough / impossible. Do they have an RSS feed you could use, maybe?
They do have an rss feed but that data also needs to be modified..
If i put their Rss Feed onto my site, is there a way to remove some of the words that they have put onto it?

Re: Modify data brought in via <?php include

Posted: Fri Jan 16, 2009 10:18 am
by kipp
fine and straightforward
Besides job security, why wouldn't this be your motto!

Re: Modify data brought in via <?php include

Posted: Fri Jan 16, 2009 10:46 am
by mattpointblank
drfb wrote:
mattpointblank wrote:The search and replace is fine and straightforward, but as PCSpectra says, actually including the file will be tough / impossible. Do they have an RSS feed you could use, maybe?
They do have an rss feed but that data also needs to be modified..
If i put their Rss Feed onto my site, is there a way to remove some of the words that they have put onto it?
Yeah, using the search and replace (as long as you're careful). Google something like MagpieRSS for using an RSS feed in PHP.
kipp wrote:
fine and straightforward
Besides job security, why wouldn't this be your motto!
Hah, well, compared to including external files, string search/replaces are straightforward!

Re: Modify data brought in via <?php include

Posted: Fri Jan 16, 2009 12:12 pm
by RobertGonzalez
str_replace their code.

Code: Select all

<?php
$output = str_replace('img src="', 'img src="http://somesite.com/', $input);
?>
This might not be exactly what you want. What it does is take all image code in their markup and prepends a URL to the image path in it.

Re: Modify data brought in via <?php include

Posted: Fri Jan 16, 2009 11:38 pm
by drfb
Everah wrote:str_replace their code.

Code: Select all

<?php
$output = str_replace('img src="', 'img src="http://somesite.com/', $input);
?>
This might not be exactly what you want. What it does is take all image code in their markup and prepends a URL to the image path in it.
I have attempted the following (and others) but lets see what people think of these and see if we can get either of them to work. I'm going a bit

Code: Select all

 
<?php
$input = file_get_contents('http://www.somesite.com/page.htm');
$output = str_replace('images/foldername', 'http://www.somesite.com/images/foldername', $input);
echo $output
?>
 

Code: Select all

 
<?php
$input = include('http://www.somesite.com/page.htm');
$output = str_replace('images/foldername', 'http://www.somesite.com/images/foldername', $input);
echo $output
?>
 

Code: Select all

 
<?php
ob_start();
include('http://www.somesite.com/page.htm');
$inc = ob_get_contents();
$testr = str_replace('images/foldername', 'http://www.somesite.com/images/foldername', $inc);
ob_end_clean();
echo $testr
?>
 

Code: Select all

 
<?php
ob_start();
$file = ob_get_contents();
include('http://www.somesite.com/page.htm');
echo str_replace('images/foldername', 'http://www.somesite.com/images/foldername', $file);
?>
 
I'm completly stumped.. None of these so far have worked..
I have tried the above and also mixing some of them around etc..
Maybe there is something that i am missing but can't seem to put the correct combination together
from other sites that i have searched.. Some of them have really good ideas but they only supply
1/4 of the code and don't explain to much..

For all of you viewing this post and supplying me with input, Thanks Heaps..
Keep it up and i believe we will get somewhere..

Well i'm off to test out some more ideas..

Re: Modify data brought in via <?php include

Posted: Sat Jan 17, 2009 9:57 am
by RobertGonzalez
Post the code you have currently that shows where you are getting the content from. You said you have that, right?

Re: Modify data brought in via <?php include

Posted: Sat Jan 17, 2009 10:14 am
by Burrito
your first try should have done it. is file_get_contents() returning anything at all?

if not, you may want to try fsockopen() to create your html string.

Re: Modify data brought in via <?php include

Posted: Sun Jan 18, 2009 2:58 am
by drfb
Everah wrote:Post the code you have currently that shows where you are getting the content from. You said you have that, right?
That's correct i do have permission to use the info (to include their html file) however they advised that they
will not modify anything on their side to assist. It is setup to work on their site so they are leaving it as is.
However they are allowing other organisations like mine to use it as it is an extra advertisment they don't
have to worry about..

Now are you meaning the code as in the URL or the html code that is at the URL i'm trying to include
or even the actual php code i am using to try and change the text? (which has been displayed above in previous post)

Re: Modify data brought in via <?php include

Posted: Sun Jan 18, 2009 3:01 am
by drfb
Burrito wrote:your first try should have done it. is file_get_contents() returning anything at all?
if not, you may want to try fsockopen() to create your html string.
How do i get it to show if it is returning anything?
When i run the test.html file it shows the info i am trying to include but doesn't make any changes..
The html stays as 'img src="images/foldername/image.gif'..

How would i run the code to try out fsockopen() ??

Re: Modify data brought in via <?php include

Posted: Sun Jan 18, 2009 11:04 am
by Burrito
if it's outputting something but not changing it, then file_get_contents() is NOT your problem. Post a small snippet it of what it returns in here that you'd like replaced and I'll take a look at it.