943,881 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2011
  • PHP RSS
Sep 7th, 2008
0

file_get_contens doesn`t work

Expand Post »
I`m trying to load the contents of a php file, change some variables through a replace, and save it again, but upon loading, the file_get_contents doesn`t parse the start of the file for some reason. I tried this on my server and on the local server.

Example :

filesample.php :

php Syntax (Toggle Plain Text)
  1. <?php
  2. $var1 = array('this' => 'that');
  3. ?>

read_file.php

php Syntax (Toggle Plain Text)
  1. <?php
  2. $fp = file_get_contents('filesample.php');
  3. echo '<pre>'.$fp.'</pre>';
  4. ?>


Output :

PHP Syntax (Toggle Plain Text)
  1. 'that');
  2. ?>

Waiting for your thoughts and experiences.
Last edited by bin_asc; Sep 7th, 2008 at 9:06 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bin_asc is offline Offline
5 posts
since May 2005
Sep 7th, 2008
0

Re: file_get_contens doesn`t work

did you view the source. sometimes pre tags don't work for me and i know that browsers like to hide php code.
Last edited by kkeith29; Sep 7th, 2008 at 10:29 pm.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Sep 8th, 2008
0

Re: file_get_contens doesn`t work

Click to Expand / Collapse  Quote originally posted by kkeith29 ...
did you view the source. sometimes pre tags don't work for me and i know that browsers like to hide php code.
I would say that kkeith has got the answer here...look at what the browser is seeing

<?php
$var1 = array('this' =>
'that');
?>

<...>

Looks like a tag to a browser ... even though it doesn't know what tag it is, so doesn't parse it, it still doesn't show it either.

php Syntax (Toggle Plain Text)
  1. <?php
  2. $fp = file_get_contents('filesample.php');
  3. echo '<pre>'.htmlspecialchars($fp).'</pre>';
  4. ?>

Cheers
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008
Sep 8th, 2008
0

Re: file_get_contens doesn`t work

Works. Thanks alot !
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bin_asc is offline Offline
5 posts
since May 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Dynamic HTML link with Nested PHP
Next Thread in PHP Forum Timeline: calling function name? i need help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC