Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create from HTML #486

Open
Tankonyako opened this issue May 23, 2022 · 2 comments
Open

Create from HTML #486

Tankonyako opened this issue May 23, 2022 · 2 comments

Comments

@Tankonyako
Copy link

How to create embed from raw html?

@oscarotero
Copy link
Owner

You can create a custom http client interface that read the html code from any different source than http. See the FileClient class created to test the library without performing any real http request:

https://github.com/oscarotero/Embed/blob/master/tests/FileClient.php
This class is used here: https://github.com/oscarotero/Embed/blob/master/tests/PagesTestCase.php#L51-L54

@str
Copy link

str commented Jul 29, 2024

@Tankonyako I used a preg replace to find all in raw HTML and replace with the right generated code to embed to preview media.

$html = preg_replace_callback('/<oembed url="(.+)"><\/oembed>/', function ($matches) {
    $url   = $matches[1];
    $embed = new Embed();
    $embed = $embed->get($url)->code->html;
    return $embed;
}, $html);

Let me know if that works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants