To find the name of a JSON file in PHP, you can use the basename()
function along with the __FILE__
constant. Here's an example:
main.php339 chars5 lines
This code will output the full name of your JSON file, with the current PHP file name as a prefix. You can modify the data.json
filename in the first line to match your actual filename. The basename()
function strips any directory information and returns just the file name itself. The __FILE__
constant refers to the current PHP file name, so you can use it to dynamically generate the full name of the JSON file. Lastly, the code uses concatenation to join the PHP file name with the JSON file name, separated by an underscore.
gistlibby LogSnag