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
  $var1 = array('this' => 'that');
?>

read_file.php

<?php
  $fp = file_get_contents('filesample.php');
  echo '<pre>'.$fp.'</pre>';
?>

Output :

'that');
?>

Waiting for your thoughts and experiences.

Recommended Answers

All 3 Replies

did you view the source. sometimes pre tags don't work for me and i know that browsers like to hide php code.

Member Avatar for langsor

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
  $fp = file_get_contents('filesample.php');
  echo '<pre>'.htmlspecialchars($fp).'</pre>';
?>

Cheers

Works. Thanks alot ! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.