List and link php files in a folder and its metatag description

If you just want the text removed after description = then try the following function:

<?php 
declare(strict_types=1); // this file wide type checking
error_reporting(-1); // display maximum errors
ini_set('display_errors', 'true'); // show errors on screen


$aDescriptions = [
  'description="come estrarre exif da immagini con php" ',
  'description = $aTags("description"] ?? FALSE',
  'description="ricavare metatags"',
];

foreach($aDescriptions as $key => $desc) :
  echo '<br>ORIGINAL ==> ' . $desc;
  echo '<br>FILTERED ==> ' . getRidOfEqualSign($desc);
  echo '<br>';
endforeach;


//========================================
function getRidOfEqualSign( string $tmp)
: string 
{
  $result = ''; // EMPTY IF FALSE

  $iPos = strpos($tmp, '=');

  $result = substr($tmp, ++$iPos); // notice the preceeding ++ 

  return $result;
}//

Please note that PHP has numerous functions that are very helpful and it is worth glancing at all the functions details for future reference,

https://www.php.net/manual/en/ref.strings.php

1 Like