Site Builder
Editing:
city-index.php
writable 0666
<?php $uriParts = array_values(array_filter(explode('/', trim($_SERVER['REQUEST_URI'],'/')))); if (count($uriParts) < 4 || $uriParts[0] !== 'geo') { http_response_code(404); exit('Invalid path'); } [$_ , $country, $state, $cityRaw] = $uriParts; $city = urldecode($cityRaw); $citySlug = strtolower(preg_replace('/\s+/', '-', $city)); $jsonFile = __DIR__ . "/{$citySlug}-biz-list.json"; $locFile = __DIR__ . "/location.txt"; function pretty_city($slug) { return ucwords(str_replace('-', ' ', $slug)); } function cap_slug_url($url){ return preg_replace_callback('#/([^/]+)/?$#', fn($m)=>'/'.ucfirst(strtolower($m[1])).'/', $url); } function cap_city_slug($tag) { $slug = strtolower(str_replace(' ', '-', $tag)); return ucfirst($slug); } function cap_slug_url_service($tag, $country, $state) { $slug = cap_city_slug($tag); return "/geo/$country/$state/$slug/"; } $prettyCity = pretty_city($city); $bizList = is_readable($jsonFile) ? (json_decode(file_get_contents($jsonFile), true) ?: []) : []; $bizNames = array_slice(array_column($bizList, 'name'), 0, 8); $namesCSV = implode(', ', $bizNames); $metaDesc = "Explore the BestDealOn local directory for {$prettyCity}, {$state}. " . ($namesCSV ? "Featured businesses: {$namesCSV}." : ""); $lat = $lon = ''; if (is_readable($locFile)) { [$lat, $lon] = preg_split('/[ ,]+/', trim(file_get_contents($locFile))) + ['', '']; } function h($s){ return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); } function haversine_km($lat1,$lon1,$lat2,$lon2){ $R=6371; $dLat=deg2rad($lat2-$lat1); $dLon=deg2rad($lon2-$lon1); $a=sin($dLat/2)**2 + cos(deg2rad($lat1))*cos(deg2rad($lat2))*sin($dLon/2)**2; return $R*2*asin(sqrt($a)); } $nearbyLinks=''; $stateCitiesFile = $_SERVER['DOCUMENT_ROOT']."/geo/json-data/{$state}.json"; if(is_readable($stateCitiesFile) && ($stateCities=json_decode(file_get_contents($stateCitiesFile),true))){ if(!$lat || !$lon){ foreach($stateCities as $c){ if(strtolower($c['city'])===strtolower($city)){ $lat=$c['lat']; $lon=$c['lon']; break; } } } if($lat && $lon){ $dists=[]; foreach($stateCities as $c){ if(strtolower($c['city'])===strtolower($city)) continue; $d=haversine_km($lat,$lon,$c['lat'],$c['lon']); $dists[]=['c'=>$c,'d'=>$d]; } usort($dists,fn($a,$b)=>$a['d']<=>$b['d']); $nearby=array_slice($dists,0,4); if($nearby){ $nearbyLinks = implode(' · ', array_map(fn($n)=> '<a href="'.h(cap_slug_url($n['c']['url'])).'" title="See all businesses in '.h(pretty_city($n['c']['city'])).', '.h($state).'">'.h(pretty_city($n['c']['city'])).'</a>', $nearby) ); } } } /* ADVERTISING CARD VARIABLES */ $ad_niches = [ 'Restaurants', 'Home Services', 'Real Estate', 'Automotive', 'Lawyers', 'Dentists', 'Plumbers', 'HVAC', 'Roofing', 'Landscaping', 'Electricians', 'Insurance', 'Medical', 'Gyms', 'Contractors' ]; $geo_phrase = "$prettyCity, $state"; $ad_keywords = strtolower(str_replace(' ', '-', "$city-$state-advertising")); $ad_card_head = "Grow Your Business in $prettyCity, $state!"; $ad_meta_keywords = strtolower($prettyCity . ", $state, advertising, " . implode(', ', $ad_niches)); $ad_btn_href = "/advertise.php?geo=" . urlencode($ad_keywords); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title><?= h("{$prettyCity}, {$state} Business Directory | BestDealOn") ?></title> <meta name="description" content="<?= h($metaDesc) ?>"> <meta name="keywords" content="<?= h("{$prettyCity} {$state}, {$namesCSV}, advertising, $ad_meta_keywords") ?>"> <link rel="canonical" href="<?= h('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) ?>" /> <meta property="og:title" content="<?= h("{$prettyCity}, {$state} Business Directory | BestDealOn") ?>"> <meta property="og:description" content="<?= h($metaDesc) ?>"> <meta property="og:type" content="website"> <meta property="og:locale" content="en_US"> <meta property="og:url" content="<?= h('https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) ?>"> <meta name="geo.placename" content="<?= h("{$prettyCity}, {$state}") ?>"> <meta name="geo.region" content="<?= h("US-{$state}") ?>"> <?php if($lat && $lon): ?> <meta name="geo.position" content="<?= h("{$lat};{$lon}") ?>"> <meta name="ICBM" content="<?= h("{$lat}, {$lon}") ?>"> <meta property="og:latitude" content="<?= h($lat) ?>"> <meta property="og:longitude" content="<?= h($lon) ?>"> <?php endif; ?> <style> :root{--brand:#5b36ff;--accent:#f4f6ff;--radius:.5rem; --logo-col-1:#551A8B;--logo-col-2:#00c853;--logo-col-3:#ff1744;} *,*::before,*::after{box-sizing:border-box;margin:0;padding:0;} body{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif; line-height:1.55;background:#fff;color:#222;} .top-bar{display:flex;justify-content:space-between;align-items:center;background:#eee;padding:.5rem 1rem;font-size:.875rem;} .logo{font-weight:900;letter-spacing:-.5px;text-decoration:none;line-height:1;} .logo span{display:inline-block;white-space:pre;} .logo .b{color:var(--logo-col-1);} .logo .d{color:var(--logo-col-2);} .logo .o{color:var(--logo-col-3);} nav.breadcrumb a{color:#0366d6;text-decoration:none;} nav.breadcrumb span{margin:0 .25rem;} header{background:var(--brand);color:#fff;padding:2rem 1rem;text-align:center;} header h1{font-size:clamp(1.8rem,5vw,2.6rem);} header p{margin-top:.3rem;font-weight:300;letter-spacing:.03em;} main{max-width:900px;margin:2rem auto;padding:0 1rem;} .biz-card{background:var(--accent);border-radius:var(--radius);padding:1.25rem 1.5rem;margin-bottom:1.5rem; box-shadow:0 1px 4px rgba(0,0,0,.08);} .biz-head{display:flex;justify-content:space-between;align-items:center;gap:1rem;} .quick-links a{display:inline-block;padding:.25rem .85rem;font-size:.75rem;font-weight:600; background:var(--brand);color:#fff;border-radius:var(--radius);text-decoration:none;} .quick-links a:hover{opacity:.85;} .biz-head h2{font-size:1.25rem;margin:0;color:var(--brand);} .biz-meta{font-size:.875rem;margin-bottom:.5rem;} .divider{border:0;height:1px;background:#d7dbe8;margin:1rem 0;} .tags,.svc{display:flex;flex-wrap:wrap;gap:.5rem;margin-top:.5rem;} .tags a.tag { cursor:pointer; } .tag,.svc a{background:var(--brand);color:#fff;padding:.25rem .6rem;font-size:.75rem;border-radius:var(--radius); text-decoration:none;} .tag.gry{background:#999;} .near-wrap{max-width:900px;margin:2rem auto 0;padding:0 1rem;text-align:center;} .near-wrap hr{border:0;height:1px;background:#d7dbe8;margin:0 0 1rem;} .near-wrap a{color:#0366d6;text-decoration:none;font-weight:600;} .near-wrap a:hover{text-decoration:underline;} .ad-card { background: #f4f7ff; border-radius: 18px; max-width: 700px; margin: 2.5rem auto 2rem; padding: 2rem 2.2rem 1.7rem 2.2rem; box-shadow: 0 2px 12px 0 rgba(48,65,105,.10); text-align: left; border: 1.5px solid #e6e8fa; } .ad-card h3 { color: #3759be; font-size: 1.3rem; margin-bottom: .75rem; } .ad-card ul { margin: .5em 0 .5em 1.1em; padding: 0; font-size: 1.07em; } .ad-card ul li { margin-bottom: .3em; color: #304a6b; line-height: 1.5; } .ad-btn { background: var(--brand,#5b36ff); color: #fff !important; display: inline-block; padding: .54em 1.1em; border-radius: 7px; text-decoration: none; font-weight: 700; font-size: 1.07em; margin-top: 1em; transition: background .18s; } .ad-btn:hover { background: #3943d2; } footer{font-size:.75rem;text-align:center;padding:2rem 0;color:#666;} @media(prefers-color-scheme:dark){ body{background:#111;color:#e8e8e8;} .top-bar{background:#222;} header{background:#2d21b6;} .biz-card{background:#1b1b1f;} .near-wrap hr{background:#333;} .ad-card {background:#202336; border-color:#353757;} } </style> </head> <body> <!-- LOGO + BREADCRUMB --> <div class="top-bar"> <a class="logo" href="/"><span class="b">BEST </span><span class="d">DEAL </span><span class="o">ON</span></a> <nav class="breadcrumb" aria-label="Breadcrumb"> <a href="/">Index</a><span>/</span> <a href="/geo/<?= h($country) ?>/<?= h($state) ?>/"><?= h($state) ?></a><span>/</span> <strong><?= h($prettyCity) ?></strong> </nav> </div> <!-- HERO --> <header> <h1><?= h($prettyCity) ?>, <?= h($state) ?></h1> <p>Trusted businesses serving <?= h($prettyCity) ?> and nearby areas</p> </header> <!-- LISTINGS --> <main> <?php if(!$bizList): ?> <div style="max-width:700px;margin:2rem auto 1.7rem auto;padding:1.1em 1.5em 1.2em 1.5em;background:#fde8e6;border-radius:14px;border:1.5px solid #fa9797;color:#c52b22;font-weight:600;box-shadow:0 1.5px 10px 0 rgba(230,110,100,0.07);"> <span style="font-size:1.16em;">🚀 <strong>Be the first to advertise in <?= h($prettyCity) ?>, <?= h($state) ?>!</strong> Your business could be the top result on this page—don't miss your chance to claim this spot before your competition does.</span> </div> <p>No businesses listed yet.</p> <?php else: foreach($bizList as $biz): $contact = "{$biz['address']}<br>{$biz['city']}, {$biz['state']} {$biz['zip']}<br>". "<a href=\"tel:{$biz['phone']}\">".preg_replace('/(\d{3})(\d{3})(\d{4})/','($1) $2‑$3',$biz['phone'])."</a>"; // Only use tags actually in location_tags, plus FL/USA $location_tags = array_map('trim', $biz['location_tags'] ?? []); $svcTags = array_unique(array_merge($location_tags, ['FL', 'USA'])); ?> <article class="biz-card"> <div class="biz-head"> <h2><?= h($biz['name']) ?></h2> <div class="quick-links"> <?php if(!empty($biz['website'])): ?><a href="<?= h($biz['website']) ?>" target="_blank" rel="noopener">Website</a><?php endif; ?> <?php if(!empty($biz['profile'])): ?><a href="<?= h($biz['profile']) ?>" target="_blank" rel="noopener">Profile</a><?php endif; ?> </div> </div> <?php if(!empty($biz['slogan'])): ?><div class="biz-meta"><?= h($biz['slogan']) ?></div><?php endif; ?> <div class="biz-meta"><?= $contact ?></div> <hr class="divider"> <p><?= h($biz['description']) ?></p> <?php if(!empty($biz['tags'])): ?> <div class="tags"> <?php foreach($biz['tags'] as $t): $tagSlug = strtolower(str_replace([' ', '_'], '-', $t)); $tagLink = "business.php?type=" . urlencode($tagSlug); $seoTitle = "See all " . h($t) . " businesses in " . h($prettyCity) . ", " . h($state); ?> <a class="tag" href="<?= h($tagLink) ?>" title="<?= $seoTitle ?>"><?= h($t) ?></a> <?php endforeach; ?> </div> <?php endif; ?> <div class="svc"><span class="tag gry">Service area:</span> <?php foreach($svcTags as $tag){ $isZip = preg_match('/^\d{5}$/', $tag); $isFL = strtoupper($tag) === 'FL'; $isUSA = strtoupper($tag) === 'USA'; $isCity = !$isZip && !$isFL && !$isUSA; if($isCity){ if(in_array($tag, $location_tags, true)){ echo '<a href="'.h(cap_slug_url_service($tag, $country, $state)).'" title="See all businesses in '.h(pretty_city($tag)).', '.h($state).'">'.h(pretty_city($tag)).'</a>'; } else { echo '<span class="tag">'.h(pretty_city($tag)).'</span>'; } } elseif($isFL){ echo '<a href="/geo/'.h($country).'/'.h($state).'/">FL</a>'; } elseif($isUSA){ echo '<a href="/geo/">USA</a>'; } else { echo '<span class="tag">'.h($tag).'</span>'; } } ?> </div> </article> <?php endforeach; endif; ?> </main> <!-- NEARBY CITIES --> <?php if($nearbyLinks): ?> <section class="near-wrap"> <hr> <div style="font-size:1.05rem;font-weight:600;color:#23486b;margin-bottom:.4rem;">Nearby cities</div> <div style="font-size:.95rem;line-height:1.8;"><?= $nearbyLinks ?></div> </section> <?php endif; ?> <!-- AD SALES CARD - always visible --> <div class="ad-card"> <h3><?= h($ad_card_head) ?></h3> <p> <strong>Want to get noticed in <?= h($prettyCity) ?>?</strong> Reach local customers actively searching for <strong><?= h($prettyCity) ?>, <?= h($state) ?> businesses</strong> and services. Put your listing, coupon, or offer in front of homeowners and shoppers—right when they’re looking. </p> <p> <strong>We help all local businesses grow.</strong> Whether you run a <?php // For the in-text verticals, hyperlink them foreach (array_slice($ad_niches, 0, 4) as $i => $niche) { $nicheSlug = strtolower(str_replace([' ', '_'], '-', $niche)); $link = "business.php?type=" . urlencode($nicheSlug); $sep = $i === 0 ? '' : ', '; echo $sep . '<a href="' . h($link) . '" title="See all ' . h($niche) . ' businesses in ' . h($prettyCity) . ', ' . h($state) . '">' . h($niche) . '</a>'; } ?> business—or any local service—our geo-targeted directory connects you with high-intent buyers in <strong><?= h($prettyCity) ?>, <?= h($state) ?></strong>. <ul> <?php foreach($ad_niches as $niche): $nicheSlug = strtolower(str_replace([' ', '_'], '-', $niche)); $link = "business.php?type=" . urlencode($nicheSlug); $seoTitle = "See all " . h($niche) . " businesses in " . h($prettyCity) . ", " . h($state); ?> <li><a href="<?= h($link) ?>" title="<?= $seoTitle ?>"><?= h($niche) ?> in <?= h($prettyCity) ?>, <?= h($state) ?></a></li> <?php endforeach; ?> </ul> </p> <p> <a class="ad-btn" href="<?= h($ad_btn_href) ?>">See Ad Placement Options</a> </p> <p style="font-size:.93em;color:#888;margin-top:.8em;"> SEO for: <?= h($prettyCity) ?> <?= h($state) ?> advertising, <?= h($prettyCity) ?> <?= h($state) ?> marketing, local <?= h($state) ?> directory, business listings, and more. </p> </div> <footer> <em>Data auto‑generated from JSON feed | © <?= date('Y') ?> BestDealOn.com</em> </footer> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel