// SECTION 7.5: ENHANCED - Update subject's age in ALL paragraphs, preserve relatives' ages
// =========================================================================================
// First, try to find the subject's birth date ANYWHERE in the content
$subject_age = null;
$found_date_str = '';
// Search for birth date patterns throughout the entire content
if (preg_match('/(' . implode('|', array_map('preg_quote', $birth_labels)) . ')\s*[:\-]\s*([^\n<]+)/i', $content, $birth_section)) {
$found_date_str = trim($birth_section[2]);
$found_date_str = rtrim($found_date_str, ',.; ');
$subject_age = tcc_parse_birth_date($found_date_str);
}
// If we found a valid age, process ALL paragraphs
if ($subject_age !== null) {
// Get the subject's name from the post title for context
$subject_name = '';
$subject_first_name = '';
if (isset($post->post_title)) {
$subject_full_name = trim($post->post_title);
$subject_full_name = preg_replace('/\s*(Biography|Bio|Profile|Wiki).*$/i', '', $subject_full_name);
$subject_full_name = trim($subject_full_name);
$name_parts = explode(' ', $subject_full_name);
$subject_first_name = strtolower(trim($name_parts[0]));
}
// Comprehensive list of relative indicators
$relative_indicators = [
'wife', 'wives', 'husband', 'husbands', 'spouse', 'spouses',
'child', 'children', 'kid', 'kids', 'son', 'sons', 'daughter', 'daughters',
'father', 'fathers', 'dad', 'dads', 'mother', 'mothers', 'mom', 'moms',
'parent', 'parents', 'brother', 'brothers', 'sister', 'sisters', 'sibling', 'siblings',
'grandfather', 'grandmother', 'grandson', 'granddaughter', 'grandchild',
'uncle', 'aunt', 'cousin', 'nephew', 'niece',
'father-in-law', 'mother-in-law', 'brother-in-law', 'sister-in-law',
'fiancé', 'fiancée', 'girlfriend', 'boyfriend', 'partner',
'ex-wife', 'ex-husband', 'ex-girlfriend', 'ex-boyfriend'
];
// Split content into paragraphs
$paragraphs = explode('
', $content);
$updated_paragraphs = [];
foreach ($paragraphs as $paragraph) {
$skip_paragraph = false;
// Skip paragraphs that mention relatives
foreach ($relative_indicators as $indicator) {
if (stripos($paragraph, $indicator) !== false) {
$skip_paragraph = true;
break;
}
}
// Skip paragraphs that mention other people's names with ages
if (preg_match_all('/\b([A-Z][a-z]+)\s*\(age\s*(\d+)\)/i', $paragraph, $other_people)) {
foreach ($other_people[1] as $person_name) {
if (strtolower($person_name) !== $subject_first_name) {
$skip_paragraph = true;
break;
}
}
}
// Only update if paragraph passed all checks
if (!$skip_paragraph) {
// Update "X years old" patterns - THIS WILL CATCH "at the age of 47"
$paragraph = preg_replace_callback(
'/(?', $updated_paragraphs);
}
Abigail Anderson, Author at TheCityCelebSkip to the content