> ## Documentation Index
> Fetch the complete documentation index at: https://docs.context.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP

> Install the PHP SDK, scrape a webpage, and retrieve brand data.

The [PHP SDK](https://github.com/context-dot-dev/context-php-sdk) requires PHP 8.1 or newer and Composer.

## Install the SDK

```bash theme={null}
composer require context-dev/context-dev-php guzzlehttp/guzzle
```

Guzzle provides the HTTP transport. If your project already has a compatible PSR-18 client and PSR-17 factories, you can keep those instead.

## Set your API key

Get a secret API key from the [dashboard](https://context.dev/dashboard). Set it in the terminal where you will run the example:

```bash theme={null}
export CONTEXT_DEV_API_KEY="ctxt_secret_..."
```

Keep the key in server-side code. Do not expose it in a browser or commit it to source control.

## Scrape a webpage

Save this as `scrape.php` beside your `vendor` directory:

```php scrape.php theme={null}
<?php

require __DIR__.'/vendor/autoload.php';

use ContextDev\Client;

$client = new Client(
    apiKey: getenv('CONTEXT_DEV_API_KEY')
);

$response = $client->web->webScrapeMd(
    url: 'https://example.com',
    useMainContentOnly: true,
);

echo $response->markdown, PHP_EOL;
```

Run it from that directory:

```bash theme={null}
php scrape.php
```

## Check the result

The example prints the page content as Markdown. Look for the `Example Domain` heading; the remaining text and formatting may vary.

```markdown Expected heading theme={null}
# Example Domain
```

If you receive an error, check the key and request details in [Troubleshooting](/optimization/troubleshooting). See the [Markdown API reference](/api-reference/web-scraping/markdown) for all parameters and response fields.

<a id="retrieve-brand-data-with-http" />

## Retrieve brand data

PHP SDK `2.14.0` requires fields from multiple lookup types in its Brand helper, so it cannot form a valid domain-only lookup. Use the SDK's low-level request method until the helper is updated. It keeps SDK authentication, retries, and error handling.

Save it separately as `brand.php`:

```php brand.php theme={null}
<?php

require __DIR__.'/vendor/autoload.php';

use ContextDev\Client;

$client = new Client(apiKey: getenv('CONTEXT_DEV_API_KEY'));

$raw = $client->request(
    method: 'post',
    path: 'brand/retrieve',
    body: [
        'type' => 'by_domain',
        'domain' => 'stripe.com',
    ],
);

$response = json_decode((string) $raw->getBody(), true, flags: JSON_THROW_ON_ERROR);
echo $response['brand']['title'] ?? 'No brand found', PHP_EOL;
```

Run `php brand.php`. It prints the company name. Keep the request path relative (`brand/retrieve`, without a leading slash) so the SDK preserves `/v1` in the base URL.

## Next steps

<CardGroup cols={2}>
  <Card title="Scrape a webpage" icon="globe" href="/guides/scrape-websites-to-markdown">
    Choose which page content to include.
  </Card>

  <Card title="Retrieve brand data" icon="palette" href="/guides/get-brand-data">
    Look up profiles with other company identifiers.
  </Card>
</CardGroup>
