1. Go to this page and download the library: Download smalot/expect library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
smalot / expect example snippets
`
use Smalot\Expect\Expect;
$expect = new Expect();
$expect->open('telnet 192.168.59.103 4002');
while (1) {
switch ($expect->expect(
array(
'escape' => array('/.*Escape character.*\n/mis', Expect::EXP_REGEXP),
'command line' => array('/.+#/', Expect::EXP_REGEXP),
),
$match
)) {
case 'escape':
var_dump('escape', $match);
$expect->write('');
break;
case 'command line':
var_dump('command line', $match);
$expect->write('show cdp');
break 2;
case Expect::EXP_TIMEOUT:
die('timeout');
case Expect::EXP_EOL:
die('eol');
}
}
while (1) {
switch ($expect->expect(
array(
'command line' => array('/(.*)[\r\n]+([^\n]+#)/mis', Expect::EXP_REGEXP),
),
$match
)) {
case 'command line':
var_dump('result', $match);
break 2;
case Expect::EXP_TIMEOUT:
die('timeout');
case Expect::EXP_EOL:
die('eol');
}
}
$expect->close();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.