PHP code example of chipslays / telegraph

1. Go to this page and download the library: Download chipslays/telegraph 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/ */

    

chipslays / telegraph example snippets


use Telegraph\Telegraph;

// Create client
$telegraph = new Telegraph;

// Create account
$account = $telegraph->createAccount(
    shortName: 'MyBlog',
    authorName: 'John Doe'
);

// IMPORTANT: Save this token!
$token = $account->accessToken();

// Create page
$page = $account->createPage(
    title: 'Hello World',
    content: 'My first Telegraph article!'
);

echo "Published: " . $page->url();

$html = <<<HTML
    <h1>Article Title</h1>
    <p>Introduction with <strong>bold</strong> text.</p>
    <img src="https://example.com/image.jpg" />
    <p>Regular paragraph with <a href="https://example.com">link</a>.</p>
    <ul>
        <li>First item</li>
        <li>Second item</li>
    </ul>
    <blockquote>Important quote</blockquote>
HTML;

$page = $account->createPageFromHtml('Blog Post', $html);