dotsunited/embed-parser

Simple utility to parse URLs in HTML or text content which are placed on its own line to turn them into embeds.

v0.4.0 2017-05-16 21:19 UTC

This package is auto-updated.

Last update: 2024-04-05 17:43:02 UTC


README

Simple utility to parse URLs in HTML or text content which are placed on its own line to turn them into embeds.

Installation

Install the latest version with Composer.

composer require dotsunited/embed-parser

Check the Packagist page for all available versions.

Usage

There is single parse function provided which parses the given content and invokes a handler callback for each URL found.

$transformedContent = DotsUnited\EmbedParser\parse($content, function ($url) {
    $embedHtml = tranformUrlToEmbedHtml($url);
    
    return $embedHtml;
});

The URL must be on its own line or surrounded only by <p> tags with no other text content to be parsed.

Text

Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore
magna aliquyam erat, sed diam voluptua.

https://youtube.com/watch?v=QcIy9NiNbmo

At vero eos et accusam et justo duo dolores et ea rebum.

HTML

<p>
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
    sed diam nonumy eirmod tempor invidunt ut labore et dolore
    magna aliquyam erat, sed diam voluptua.
</p>

<p>
    https://youtube.com/watch?v=QcIy9NiNbmo
</p>

<p>
    At vero eos et accusam et justo duo dolores et ea rebum.
</p>

License

Copyright (c) 2017 Dots United GmbH. Released under the MIT license.