Reputation: 139
My requirement is to read the content of a php file and show the content in front end. For this I have used
$section = file_get_contents('test.php');
var_dump($section);
?>
But it is printing the values, and after some charater, it is just printing ... not the complete content. I have tried to print through echo and print_r method but in no case i got the full content.
My app.php is something like this :
<?php
$data = array(
array('id' => 1, 'first' => "abc", 'last' => 'def', 'email' => '[email protected]'),
array('id' => 2, 'first' => "ghi", 'last' => 'jkl', 'email' => '[email protected]'),
array('id' => 3, 'first' => "mno", 'last' => 'pqr', 'email' => '[email protected]'),
array('id' => 4, 'first' => "stu", 'last' => 'vwx', 'email' => '[email protected]'),
array('id' => 5, 'first' => "Y", 'last' => 'Z', 'email' => '[email protected]'),
);
echo json_encode(array(
'success' => true,
'message' => 'loading data',
'data' => $data
));
?>
Upvotes: 4
Views: 5202
Reputation: 21
Hey I know its bit late but i hope someone can get help from here...
These are configurable variables in php.ini:
Try to find ; XDEBUG Extension
zend_extension = "your path to php/zend_ext/php_xdebug-2.2.3-5.4-vc9-x86_64.dll"
[xdebug]
xdebug.var_display_max_depth = 10
Of course, these may also be set at runtime via ini_set()
, useful if you don't want to modify php.ini and restart your web server but need to quickly inspect something more deeply.
ini_set('xdebug.var_display_max_depth', 10);
Hope this help someone!
Upvotes: 2
Reputation: 8821
You need to escape characters like <
and >
to <
and >
.
var_dump(htmlentities($section));
Or:
echo htmlentities($section);
If you do a 'view source' in your browser you'll see that the rest is actually there but your browser is trying to interpret the text as HTML.
Also note that file_get_contents
doesn't execute
the PHP (test.php in your example); it just reads the file as if it's a text-file. You might want to have a look at include, include_once, require or require_once if you want the code in the file to actually be executed.
Upvotes: 4
Reputation:
you try to echo code it will try to parse it, so pass it through htmlspecialchars($source) and it should work.
Something like this:
<?php
echo "<pre>";
echo htmlspecialchars(file_get_contents('test.php'));
echo "</pre>";
?>
Upvotes: 3