1. Go to this page and download the library: Download nullform/telegraphus 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/ */
nullform / telegraphus example snippets
use Nullform\Telegraphus\ApiClient;
use Nullform\Telegraphus\Types\Account;
$client = new ApiClient();
$account = new Account();
$account->author_name = 'John Doe';
$account->author_url = 'https://www.google.com/';
$account->short_name = 'john';
try {
$client->createAccount($account);
$token = $account->access_token;
$client->setToken($token);
// ...
} catch (\Exception $exception) {
// ...
}
use Nullform\Telegraphus\ApiClient;
use Nullform\Telegraphus\Parser;
$token = 'token';
$client = new ApiClient($token);
$html = '<h1>Title</h1>'
. '<div>First paragraph</div>'
. '<div>Second <span>paragraph</span></div>'
. '<footer>Copyright</footer>';
// Note that not all HTML tags are available in Telegra.ph.
// Available tags: a, aside, b, blockquote, br, code, em, figcaption, figure, h3, h4,
// hr, i, iframe, img, li, ol, p, pre, s, strong, u, ul, video.
$parser = new Parser();
// You can replace or delete tags
$parser->addTagReplaceRules([
'h1' => 'h3', // Convert <h1> to <h3>
'div' => 'p', // Convert <div> to <p>
'span' => 'b', // Convert <span> to <b>
'footer' => false, // Remove <footer>
]);
try {
$page = $client->createPage(
'Test page',
$parser->htmlToTelegraphContent($html)
);
// ...
} catch (\Exception $exception) {
// ...
}
use Nullform\Telegraphus\ApiClient;
$token = 'token';
$client = new ApiClient($token);
try {
$pageList = $client->getPageList();
foreach ($pageList->pages as $page) {
// ...
}
} catch (\Exception $exception) {
// ...
}