PHP code example of chaostangent / php-ass

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

    

chaostangent / php-ass example snippets




use ChaosTangent\ASS\Reader;

$reader = new Reader();
$script = $reader->fromFile(__DIR__.'/examples/example.ass');

foreach ($script as $block) {
    echo $block->getId().PHP_EOL;

    foreach ($block as $line) {
        echo $line->getKey().': '.$line->getValue();
    }
}

$script = new Script('[Script Info]', 'mytestscript.ass');

if ($script->isASSScript()) {
    // do more processing
}

$script->parse();

foreach ($script as $block) {
    // block processing
}

if ($script->hasBlock('Script Info')) {
    $script->getBlock('Script Info');
}

$scriptInfoBlock->getTitle();
$scriptInfoBlock->getWrapStyle();
$scriptInfoBlock->getScriptType();

$scriptInfoBlock[123]; // line 124 of this block

foreach ($scriptInfoBlock as $line) {
    // line processing
}

$styleLine->getName();
$styleLine->getPrimaryColour();
$dialogueLine->getLayer();
$dialogueLine->getText();

$dialogueLine->getTextWithoutStyleOverrides();

$dialogueLine->getKey(); // == 'Dialogue'
$dialogueLine->getValue(); // e.g. 0,0:00:00.98,0:00:05.43,ED_English,,0,0,0,,{\fad(100,200)\blur5\c&H000010&\3c&H80A0C0&}My destiny,

foreach ($block as $line) {
    if ($line instanceof Dialogue) {
        echo $line->getTextWithoutStyleOverrides().PHP_EOL;
    }
}
shell
composer