I have a JS library file of variables (caption strings) used by server-side JavaScript. Can I read/interpret that from PHP?
The path to the data isn’t the issue, but whether PHP can read/use the JS variables. Currently I’ve the same variable stored in both a JS file and PHP include with obvious scope for changes getting out of synch. I’ve tried reading the PHP from the server-side JS without joy but was wondering if – with suitable parsing – if PHP could extract/use the JS variables.
I repeat all data involved is server-side on the same server. Sorry if I’ve missed this being answered before but PHP/JS questions are (even if mis-titled) seemingly all about passing data between client and server side processes – which isn’t my scenario.
Later – clarification:
The s/s JavaScript is part of a web interface to an image database where I can’t alter the API. It doesn’t support creating emails (for file requests) thus I am having to do that via PHP. Work scope/budget precludes re-writing a new d/b interface, rather we ‘just’ ned to be able to send an email. IOW, I realise you wouldn’t choose to be trying to do this if starting from scratch! Also, I don’t think I can do s/side AJAX to fetch variables or do PHP smtp mail as the JS environment seemingly isn’t designed for that degree of s/s processing pre HTML page delivery.
It sounds like you have config values (ie the captions) in the JS code.
If you want to keep it this way, my suggestion would be to split the config itself into a discrete .JS file, which would contain just the variable definitions but no actual JS code.
Then you should be able to simply parse it in PHP using
json_decode(). Job done.