Jump to content

not even sure this is possible with a file_get_contents


sandbudd

Recommended Posts

What I am trying to do is pull the content of another page which works fine and then do echo statements.  It does display the content of the page but not the echo statements.

 

outside page

 


lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum <?php echo $stateinsert ?> lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum <?php echo $cityinsert ?> <?php echo $stateinsert ?> lorem ipsum lorem ipsum lorem ipsum lorem ipsum  <?php echo $countyinsert ?> Lorum Ipsom Lorum Ipsom Lorum Ipsom </p>

 

<?php 
$cityinsert = "Auburn";
$stateinsert = "Alabama";
$countyinsert = "Jefferson";
$table = "auburnAL"; 

?>
<?php
$d = file_get_contents("http://mysite.com/includes/leftcopy.php");
echo ($d);
?>

 

It displays the lorem ipsum  but won't display the echo statements.

Link to comment
Share on other sites

Those echo statements will be executed on the external page, not in your script.  So all the echoed variables are blank when the echo executes.

 

Instead you might want to make them placeholders like "%STATEINSERT%" and do a str_replace() on $d after file_get_contents().

Link to comment
Share on other sites

It is quite simple, the PHP script you are calling resides on a different server.  When you call a file using 'file_get_contents()', and you specify the file path with 'http://', the file gets parsed by the server BEFORE delivery of the contents.  He had you to place 'placeholders' in your script where you wanted the data to show.  Placeholders are unique string patterns that isn't normally used in a page layout.  You can make them anything you want, but they must be unique.

 

He then had you to do a simple string_replace function to find you placeholders, and replace them with your desired variables.

Link to comment
Share on other sites

jcbones explained it well.  If both scripts are on the same server you could consider using sessions or include() instead of file_get_contents().  Sessions allow you to share data between scripts, and include() will allow leftcopy.php to access the variables you have set in your script.  The reason is that include() runs in the same copy of php, but file_get_contents() starts a new copy of php to run leftcopy.php in, and it doesn't know about the variables you set.

Link to comment
Share on other sites

Hey everyone thanks for the help but I need to know how to continue the echo statement... this is what I tried but does not work.

 



<?php 
$cityinsert = "Auburn";
$stateinsert = "Alabama";
$countyinsert = "Jefferson";
$table = "auburnAL"; 

?>
<?
$d = file_get_contents("http://mysite/includes/leftcopy.php");
echo $d = str_replace("%STATEINSERT%", $stateinsert, $d);
echo $d = str_replace("%CITYINSERT%", $cityinsert, $d);
?>

Link to comment
Share on other sites

Tried this with no luck

 


<?php
$d = file_get_contents("http://restaurantsanddiners.com/includes/leftcopy.php");
echo $d = str_replace("%STATEINSERT%", $stateinsert, $d);
echo $d .= str_replace("%CITYINSERT%", $cityinsert, $d);
?>

Link to comment
Share on other sites

It should look like this:

 

$d = str_replace("%STATEINSERT%", $stateinsert, $d);
$d = str_replace("%CITYINSERT%", $cityinsert, $d);
echo $d;

 

You can add as many of the str_replace() lines as you want.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.