-
-
Notifications
You must be signed in to change notification settings - Fork 309
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
Parse a HTML string #18
Comments
Hi. |
Hi again, @nazieb
You can create your own url resolver and use it on create a new Url instance: $resolver = new GuzzleResolver($guzzleData);
$url = new Embed\Url($resolver); //You can provide directly the resolver instead the url string
$info = Embed\Embed::create($url); You can set your url resolver as default to use it always, not only the main url: Embed\Url::setDefaultResolver('GuzzleResolver'); Please, let me know if this is what you need. |
Hello Oscar, It's really nice of you to build the custom URL resolver. That might come For the example, in my app the HTML is already stored in the database Without Wax, Ainun Nazieb On Sat, Mar 22, 2014 at 1:48 AM, Oscar Otero notifications@github.comwrote:
|
Hi. //Create your own resolver class that implements the Embed\UrlResolvers\UrlResolverInterface and instance it:
$resolver = new MyOwnResolver();
//Now set the information you have stored in your database (url, content, etc) to prevent the request
$resolver->setUrl($url);
$resolver->setContent($content);
//This can be set by default:
$resolver->setMimetype('text/html');
$resolver->setHttpCode(200);
//Ok, you can now get all information about this url
$info = Embed\Embed::create($resolver); |
Wow, that's nice solution. I'm fine with the http request to another API I'll test your example right away. Thanks for the support and this great
|
With the new Guzzle5 resolver: use GuzzleHttp\Client;
use GuzzleHttp\Event\BeforeEvent;
use GuzzleHttp\Message\Response;
use GuzzleHttp\Stream\Stream;
$html = file_get_contents('http://whatever'); // HTML string
$client = new Client();
$client->getEmitter()->on('before', function(BeforeEvent $e) use ($html) {
$body = isset($html) ? Stream::factory($html) : null;
$e->intercept(new Response(200, [], $body));
});
$embed = Embed::create($url = 'dummy', [ // $url must not be empty
'resolver' => [
'class' => \Embed\RequestResolvers\Guzzle5::class,
'config' => [ 'client' => $client ],
],
]); |
Hello,
Is there any way to parse a HTML string instead of a URL? In my app I already grab the HTML via Guzzle HTTP and I want to parse from the response, not to request the URL all over again.
The text was updated successfully, but these errors were encountered: