Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

i am developing a function which return a value on give file name but include() in not return able which function should i use get_file_contents() is return able function or is there is any other class or function which return a value of given file

function  myfunction($file){
$get = include($file);
return $get;

}

something like this

myfunction('/home/files/test.php');
share|improve this question

closed as off topic by Su', John Conde Sep 22 '12 at 20:20

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
You can return values from an included file, but this is probably not what you are after. include() and file_get_contents() do different things, one is not "better" than the other. Does file_get_contents() not do what you require? –  w3d Sep 22 '12 at 20:19
add comment

1 Answer 1

By your vague question, I'm guessing you want to retrieve the file name?

Using either include or file_get_contents will not yield the results you want, not at all. include executed the files, whereas file_get_contents retrieves the actual textual representation of the file(gets the contents).

What you want is basename.

Given a string containing the path to a file or directory, this function will return the trailing name component.

From: http://php.net/manual/en/function.basename.php

Probable usage of the function within your script would be as follows:

function myfunction($file) {
   return basename($file);
}
share|improve this answer
    
I agree the question is vague, but I don't think basename() is the solution the OP is after. From the example given, the OP would seem to require the contents (in some form) of the specified file. –  w3d Oct 16 '12 at 14:29
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.