Purge cache subdirectories

Hello!
I am working on a function that purge the cache of subdirectories of a specific directory.
If anyone has an idea
This is my essay

<?php
class Custom_Tools_Cflare
{
    public function clear($dir,$host,$uri) {
        $ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/xxxxxxxxxx/purge_cache");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"files\":[\"http://xxxx.com/".$dir."/".$uri."\",{\"url\":\"http://xxxx.com/".$dir."/".$uri."\",\"headers\":{\"X-Forwarded-Host\":\"".$host."\",\"X-Host\":\"xxxxxxx.com\"}}]}");
		curl_setopt($ch, CURLOPT_POST, 1);

		$headers = array();
		$headers[] = "X-Auth-Email: [email protected]";
		$headers[] = "X-Auth-Key: xxxxxxxxxxx";
		$headers[] = "Content-Type: application/json";
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);
		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		curl_close ($ch);
    }
	public function myfunction(){
	
		$di = new RecursiveDirectoryIterator('http://xxxxx.com/');
		foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
		$file->clear($di,$host,$uri);
		}
	}
}

Thanks in advance

On what?

about the code for sure!

You need to be more clear on that. Either it works - then there is not much to discuss - or it doesnt, which is when you need to provide more details.

It doesn’t work so I ask and I have tried as you can see.

Hello!
I want to purge cache of all my internal urls, for example php.net/intro … with Cloudflare, this is my php script , How can I solve my code?
(I tried to format the code but It failed)
Thanks in advance

>  <?php
> class Custom_Tools_Cflare
> {
> $urlContent = file_get_contents('http://php.net/');
>     public function clear($dir,$host,$uri) {
>         $ch = curl_init();
> 
> 		curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/xxxxx/purge_cache");
> 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> 		curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"files\":[\"http://xxxxxxx/".$dir."/".$uri."\",{\"url\":\"xxxx.com/".$dir."/".$uri."\",\"headers\":{\"X-Forwarded-Host\":\"".$host."\",\"X-Host\":\"xxxxx\"}}]}");
> 		curl_setopt($ch, CURLOPT_POST, 1);
> 
> 		$headers = array();
> 		$headers[] = "X-Auth-Email: xxxxxxxxxxxxx";
> 		$headers[] = "X-Auth-Key: xxxxxxxxxxxx";
> 		$headers[] = "Content-Type: application/json";
> 		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
> 
> 		$result = curl_exec($ch);
> 		if (curl_errno($ch)) {
> 			echo 'Error:' . curl_error($ch);
> 		}
> 		curl_close ($ch);
>     }
> 	
> 	public function myfunction(){
> 	$html=file_get_contents('xxxxxxxxx');
> 	$dom=new DOMDocument();
> 	@$dom->loadHTML($html);
> 
> 	$xpath=new DOMXPath($dom);
> 	$hrefs=$xpath->evaluate("/html/body//a");
> 	for($i=0;$i<$hrefs->length;$i++){
> 	$href=$hrefs->item($i);
> 	$url=$href->getAttribute('href');
> 	if (substr( $url, 0, 18 ) === "https://xxxxxxxxxxxxx") {
>     echo $url.'<br />';
> 	clear($dir,$host,$url);
> }
> 	
> }
> }
> }