PHP code example of sharpapi / laravel-content-detect-phones

1. Go to this page and download the library: Download sharpapi/laravel-content-detect-phones 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/ */

    

sharpapi / laravel-content-detect-phones example snippets




namespace App\Http\Controllers;

use GuzzleHttp\Exception\GuzzleException;
use SharpAPI\ContentDetectPhones\ContentDetectPhonesService;

class ContentController extends Controller
{
    protected ContentDetectPhonesService $phoneDetectionService;

    public function __construct(ContentDetectPhonesService $phoneDetectionService)
    {
        $this->phoneDetectionService = $phoneDetectionService;
    }

    /**
     * @throws GuzzleException
     */
    public function detectPhoneNumbers(string $text)
    {
        $statusUrl = $this->phoneDetectionService->detectPhones($text);
        
        $result = $this->phoneDetectionService->fetchResults($statusUrl);

        return response()->json($result->getResultJson());
    }
}

use GuzzleHttp\Exception\ClientException;

try {
    $statusUrl = $this->phoneDetectionService->detectPhones('Contact us at +1 (800) 555-1234 or 555-6789');
} catch (ClientException $e) {
    echo $e->getMessage();
}