Duplicate Content Fingerprinter
Creates stable fingerprints for detecting duplicate or near-duplicate pages.
Function signature
ogFingerprintContent(content, options = array())
Categories
- Security
Parameters
contentRaw content normalized before fingerprinting.optionsOptional documented policy controls for the helper.Return value
Public-safe status string returned by the function for controller branching or logging.
- success
- message
- data
Compatibility
Existing function name, slug, path, and call order preserved; advertised metadata corrected to the actual source behavior.
Minimum PHP version: 7.4
Security notes
Use caller-owned allowlists and context-specific escaping; validate file paths, routes, email tokens, cart totals, discount rules, and tax-region rules before production use.
Code
<?php
/*
* Copyright (c) 2026 Jeffery L. Paris <jparis@phpog.com>.
* Free for personal and internal use. Paid project use requires visible credit
* to Jeffery L. Paris. Corporate use requires a paid license fee unless a
* separate written license states otherwise.
*/
/**
* Creates stable fingerprints for detecting duplicate or near-duplicate pages.
*
* Primary use case: SEO audits and content management.
* Typical inputs: content text, normalization rules.
* Typical output: fingerprint string.
*
* Implementation note: Use fingerprints as signals, not automatic deletion triggers.
*
* @param string $content Content to fingerprint.
* @param array $options Normalization options.
* @return array Fingerprint data.
*/
function ogFingerprintContent($content, $options = array()) {
$result = array(
'success' => false,
'message' => '',
'data' => array()
);
$content = (string)$content;
if (!is_array($options)) {
$options = array();
}
if (empty($content)) {
$result['message'] = 'Content is required.';
return $result;
}
$normalized = strtolower(strip_tags($content));
$normalized = html_entity_decode($normalized, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$normalized = preg_replace('/\s+/', ' ', $normalized);
$normalized = trim($normalized);
if (!empty($options['remove_numbers'])) {
$normalized = preg_replace('/[0-9]+/', '', $normalized);
$normalized = preg_replace('/\s+/', ' ', trim($normalized));
}
$tokens = array();
foreach (explode(' ', $normalized) as $word) {
$word = trim($word);
if (strlen($word) >= 3) {
$tokens[] = $word;
}
}
$token_string = implode(' ', $tokens);
$result['success'] = true;
$result['message'] = 'Content fingerprint created.';
$result['data'] = array(
'fingerprint' => hash('sha256', $token_string),
'word_count' => count($tokens),
'normalized_sample' => substr($token_string, 0, 120)
);
return $result;
}