Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Perhaps simply</p> <pre><code>preg_match('/[0-9]*/', $output, $matches); </code></pre> <p>If I'm not mistaken...<br/></p> <p>To be sure:</p> <pre><code>preg_match('Counts is :([0-9]*)[^0-9]*([0-9]*)/',$output,$matches); </code></pre> <p>Also have a look <a href="https://stackoverflow.com/questions/17468367/interactive-control-of-a-program-using-php#comment25384148_17468367">at this question</a> to find ouy how to use PHP and C(++) interactively</p> <p>A quick, and hacky ugly messy workaround could be:</p> <pre><code>printf("%d",ar[0]); return ar[1];//end main function </code></pre> <p>Then, in your PHP script:</p> <pre><code>$a = array(shell_exec('/home/technoworld/Videos/LinSocket/client "nice bad"'), shel_exec('echo $?'); ); </code></pre> <p>Then get the last numeric value from the output string, (<code>preg_match('/([0-9]*)\w*$/',$a[0],$matches);</code> should do it, and <code>$a[1]</code> will contain the value of <code>ar[1]</code> of the main.cpp file, because that was the exit code. Note that exit codes <em>aren't for show</em>. The signify something! Changeing them is generally a bad idea. I'd just change my main.cpp, and add the line:</p> <pre><code>printf("@ar[0]=%d;ar[1]=%d@",ar[0],ar[1]); </code></pre> <p>This prints a clearly formatted string, which is easy to parse using a regular expression. Assuming <code>*ar</code> held values 123 and 456 respectively:</p> <pre><code>preg_match_all('/\]\=([^;@]*)/',$a[0],$matches); var_dump($matches[1]);//[123,456] </code></pre> <p>Or better stil:</p> <pre><code>$parts = explode('@', $a[0]); echo $parts[1];//ar[0]=123;ar[1]=456 </code></pre> <p>Bottom line:</p> <p>Add this to your <code>main</code> function in <em>main.cpp</em>:</p> <pre><code>printf("@ar[0]=%d;ar[1]=%d@",ar[0],ar[1]); </code></pre> <p>and, to get the int values in php:</p> <pre><code>$a = array(shell_exec('..')); preg_match_all('/[^=]*\=([^;@]*)/',$a[0],$matches); var_dump($matches[1]); </code></pre> <p>That should do it.</p> <pre><code>$a = array(); $b = array(); if (preg_match_all('/[^=]*\=([^;@]*)/', shell_exec('your command'), $matches)) { $a[] = (int) $matches[1][0];//optionally cast to int $b[] = (int) $matches[1][1]; } </code></pre> <p>That's all... not sure why <code>$a</code> and <code>$b</code> need to be arrays, but that's probably because you're going to call the <code>client</code> bin a couple of times.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload