Using MATLAB with PHP (with parameters)

 $command = "matlab -sd ".$inputDir." -r phpcreatefile('".$outputDir."\\".$filename."')";
  • sd “startdir”: the startup directory for MATLAB, in this case we set it to match the location of function phpcreatefile
  • -rstatement“: starts MATLAB and executes the specified MATLAB statement.

string exec ( string command [, array output [, int return_var]])

exec() executes the given command, however it does not output anything.

  •  returns the last line from the result of the command.
  • output argument is present, the specified array will be filled with every line of output from the command.
  • Line endings, such as \n, are not included in this array.
  • Note that if the array already contains some elementsexec() will append to the end of the array.
  • If you do not want the function to append elements, call unset() on the array before passing it to exec().
  • if return_var argument is present along with the array argument, then the return status of the executed command will be written to this variable.
  • Return codes can be a bit arbitrary. Basically though, any non-zero return value is an error.
    • All exec knows about is lines of output; it has no further knowledge of what is in those lines.
      $output = array();
      exec("awk -v RS=\",\" '/some_text/' test1.html", $output);
      echo implode("\n", $output);

PHP parameters

PHP中的所有变量都是以 $ 符号开始的。不需要在设置变量之前声明该变量。根据变量被设置的方式,PHP 会自动地把变量转换为正确的数据类型。

自 PHP 3 起可用 print $HTTP_POST_VARS[‘username’];


echo $downloadFile_path.$downloadFileName;

implode — Join array elements with a string

$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated; // lastname,email,phone
// Empty string when using an empty array:
var_dump(implode('hello', array())); // string(0) ""


used to displays structured information (type and value) about one or more variables.


destroys the specified variables.

/*foreach($out as $line) {
echo $line;

 PHP global

get the last value & key of an array in PHP:

  • $lastValue = end($array);
    • $lastKey = key($array); // current key, which is the last since you called end()
    • end(array_keys($myarr))
  • array_pop(array_keys($array));
  • echo $array[count($array) – 1]; //This only works if you have numerical arrays. Fails with associate arrays.
  • $last_key = key( array_slice( $array, -1, 1, TRUE ) );
$array = array(
    'first' => 123,
    'second' => 456,
    'last' => 789, 
end($array);         // move the internal pointer to the end of the array
$key = key($array);  // fetches the key of the element pointed to by the internal pointer



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: