( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
$md_file = 'c:\wamp64\www\thebrand\wow2\tools\resources\brandinsights.md';
$content = file_get_contents($md_file);
$lines = explode("\n", $content);
$items = [];
$current_title = '';
foreach ($lines as $line) {
$line = trim($line);
if (empty($line)) continue;
// Check for URL
if (strpos($line, 'https://') !== false) {
// If line starts with http, previous non-empty line was title
if (strpos($line, 'https://') === 0) {
$url = $line;
$title = $current_title;
} else {
// Title and URL on same line
// format: Title https://...
$parts = explode('https://', $line, 2);
$title = trim($parts[0]);
$url = 'https://' . $parts[1];
}
if (!empty($title) && !empty($url)) {
// Generate a simple ID
$id = count($items) + 1;
$items[] = [
'id' => (string)$id,
'title' => $title,
'url' => $url,
'category' => 'Brand Insights' // Default category
];
$current_title = ''; // Reset
}
} else {
// Potential title for next line
$current_title = $line;
}
}
$json_output = json_encode(['brand_insights' => $items], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
file_put_contents('c:\wamp64\www\thebrand\wow2\tools\resources\brand_insights\items.json', $json_output);
echo "Parsed " . count($items) . " items.\n";
?>