📎 AI Summary:
The thread discusses challenges in returning strings from PHP scripts called via batch files, with the original poster struggling to obtain a string output from PHP functions. A user suggests switching to PowerShell for greater flexibility, while Bear asks for clarification on the correct method to retrieve string values from PHP, indicating that the current approach is not working as intended. Overall, the conversation highlights difficulties in integrating PHP with batch scripting and a need for proper techniques to handle string returns.

Bear

Well-Known Member
Joined
Sep 29, 2016
Messages
128
Thread Author #1
I'm having a hell of a time getting php to return a string.
I don't know where they are going to install my batch file so I set the file location via %~dp0.
there are 2 functions in my .php file, one to process color another to process Joomla's Version. The joomla one worked fine until I made it a function but my main concern is I can't return a simple string!!
I've tried everything I can think of.
I want parameter #2 to be the function choice and param 1 to be the variable passed to the function.
Code:
:: SET git_repo & branch to use by deafult
SET scriptDir=%~dp0
SET git_repo=https://github.com/joomla/joomla-cms.git
SET git_branch=4.0-dev
SET Message=Select branch to be used:  press enter FOR branch: [%GIT_BRANCH%]
SET new=false
SET update=false
SET uninstall=false
SET verbose=false
SET dirname=joomla-cms
SET _params=%*

SETLOCAL enabledelayedexpansion
:: SET local dirname
FOR %%* in (.) do SET localDir=%%~n*
echo on
FOR /f %%a in ('CALL php %~dp0jver.php "%CD%" ') do SET JVersion=%%a
echo %JVersion%




ENDLOCAL
goto:eof


php file:
/* $argv[1] is first parmater AFTER call */
$one = $argv[1];
$two = $argv[2];


$bear="Are you sure you want to do this?  Type 'yes' to continue: ,";
return $bear ;


function hi($bear){
$temp = "HI BEAR!, here's your var:" . $bear . " right?";
return $temp . PHP_EOL;
}

function jver($version){
require_once $argv[1] . '/libraries/src/Version.php';
$version = Version::MAJOR_VERSION . '.' . Version::MINOR_VERSION;
return $version . PHP_EOL;
}
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
PHP isn't really meant to be used as a client side language I'd also use Powershell over a batch file you have a lot more flexibility with your code and in the long run much easier to use.
 

Bear

Well-Known Member
Joined
Sep 29, 2016
Messages
128
Thread Author #3
I get that, but it would be really helpful if you could explain the proper way to get a return string. This used to be a common way to do things.