0

I'm trying to get the output from a java application that would use the below code to output values

System.out.println(object.getNumber(3));
System.out.println(object.getNumber(4));

I'm using exec("somejavapath javaName", $output) and print_r($output) to get that output array to print. I know it will get the values but I wanted to get into a certain format So instead of

Array
(
[0] => 34
)

I want something like this

Array
(
[0] => 3
[1] => 4
)

Does anyone know what I could do to get this format?

Thanks

4
  • What exactly do you want? One digit pr array-element? Commented Oct 6, 2013 at 22:35
  • Not really one digit per array element but rather for every println called to have its own array element Commented Oct 6, 2013 at 22:44
  • Shouldn't exec($cmd, $output); fill $output with one line of output being saved into one array element? Commented Oct 6, 2013 at 22:59
  • yes.. that's what I said. I was wondering if there was a way to set the format so it won't be that way. Commented Oct 7, 2013 at 1:14

2 Answers 2

1

If you are not expecting comas in the output from java application , include a coma between the two values :

System.out.println(object.getNumber(3));
System.out.println(",");    // Print a coma in between
System.out.println(object.getNumber(4));

Then

$values_array = explode( ',', $output );
Sign up to request clarification or add additional context in comments.

Comments

0

You can use explode to break the content up using a delimiter, in this case, a line-break (\n).

$var = explode('\n', $output); // split output by line breaks

2 Comments

doesn't this only work for if the second parameter is a string?
@user1709294: Yep, and actually, it looks like exec already does what you want by putting each line in a separate entry in the array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.