PHP code example of candysax / telegraph-node-converter
1. Go to this page and download the library: Download candysax/telegraph-node-converter 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/ */
candysax / telegraph-node-converter example snippets
$nodes = HTML::convertToNode('<p>Hello <b>world</b></p>');
$nodes->array();
$nodes->json();
$dom = new DOMDocument();
$dom->loadHTML('<p>Hello world <a href="https://example.com/">link</a></p>');
$nodes = HTML::convertToNode($dom)->json();
$html = Node::convertToHtml([
[
'tag' => 'p',
'children' => [
'Hello ',
[
'tag' => 'b',
'children' => [
'world',
],
],
],
],
]);
$html->string();
$html->dom();
$input = '<p>Hello <b>world</b> <a href="https://example.com/">link</a></p>';
HTML::convertToNode($input)->convertToHtml()->convertToNode()->convertToHtml()->string();
use GuzzleHttp\Client;
use Candysax\TelegraphNodeConverter\HTML;
function createPage() {
$client = new Client();
$client->request('POST', 'https://api.telegra.ph/createPage', [
'form_params' => [
'access_token' => 'your_telegraph_token',
'title' => 'Example',
'content' => HTML::convertToNode(
'<p>Hello world <a href="https://example.com/">link</a></p>'
)->json(),
],
]);
}
use GuzzleHttp\Client;
use Candysax\TelegraphNodeConverter\HTML;
function getPageContent() {
$client = new Client();
$response = $client->request('POST', 'https://api.telegra.ph/getPage', [
'form_params' => [
'path' => 'path_to_the_telegraph_page',
'return_content' => true,
],
])->getBody();
$data = json_decode($response, true);
return Node::convertToHtml($data['result']['content'])->string();
}