Hi,

I have a forum when members posting a lot of images links. I would like to organize the page but I don't really know how since I'm lack the knowledge of php :| .

Here it how it's look like now:

IS:

TP:

and so on with a lot of images hosting and links.

I would like to recognize "IS:" "TP:" and receive every links below them and put them in drop down menu, so it's look like that:
[IS] [TP]
or vertical
[IS]

[TP]

and when you click on one of them, it's look like that:
Clicked on IS:
[IS] [TP]

or vertical. Clicked on TP
[IS]

[TP]

I would be very very thankful for your help

Dani AI

Generated

Recommended approach: parse each post on the server (either at render time or on post-save) and build an associative array of label => [urls] (labels like "IS" and "TP"). Render compact toggle blocks for each label and attach a small client-side toggle. This keeps logic out of the browser DOM-scan and makes the output predictable and cacheable. As suggested, jQuery can handle the UI; as noted, the parser must run where the raw post field is available (database -> template). Pre-process or cache parsed HTML to avoid expensive regex work on every view.

A simple, robust PHP pattern is: split the raw post into lines, treat lines that look like LABEL: as group headers, extract http(s)://... URLs from subsequent lines, then render safe HTML. The snippet below demonstrates the core idea — remember to run htmlspecialchars on output and to whitelist/validate protocols before linking.

function group_links_by_label($text) {
    $lines = preg_split('/\r\n|\r|\n/', $text);
    $groups = [];
    $current = null;
    foreach ($lines as $line) {
        $line = trim($line);
        if ($line === '') continue;
        if (preg_match('/^([A-Za-z0-9_-]{1,10}):\s*$/', $line, $m)) {
            $current = $m[1];
            if (!isset($groups[$current])) $groups[$current] = [];
            continue;
        }
        if (preg_match_all('/https?:\/\/[^\s<>"\']+/i', $line, $m)) {
            if ($current === null) $current = 'Links';
            foreach ($m[0] as $url) $groups[$current][] = $url;
        }
    }
    return $groups;
}

// render example (drop into template)
$groups = group_links_by_label($post_text);
$id = 0;
foreach ($groups as $label => $urls) {
    $id++;
    echo '<div class="link-group">';
    echo '<button class="toggle" data-target="lg-'.$id.'" aria-expanded="false">'.htmlspecialchars($label).'</button>';
    echo '<div id="lg-'.$id.'" class="links" style="display:none">';
    foreach ($urls as $u) {
        $safe = htmlspecialchars($u);
        echo '<a href="'.$safe.'" target="_blank" rel="noopener noreferrer nofollow">'.$safe.'</a><br>';
    }
    echo '</div></div>';
}

A tiny client-side toggle (vanilla JS) keeps dependencies minimal; jQuery slideToggle() can be swapped in for animation if desired.

document.addEventListener('click', function(e){
  var t = e.target;
  if (!t.classList.contains('toggle')) return;
  var id = t.getAttribute('data-target');
  var el = document.getElementById(id);
  if (!el) return;
  var visible = window.getComputedStyle(el).display !== 'none';
  el.style.display = visible ? 'none' : 'block';
  t.setAttribute('aria-expanded', visible ? 'false' : 'true');
});

Troubleshooting notes: if the forum auto-converts URLs to anchors, run grouping on the raw stored text or use PHP DOMDocument to extract anchors safely. Cache the parsed output (or store it on post-save) to avoid repeated regex on every page view. Always escape output and restrict link protocols to avoid XSS and tabnabbing (use rel="noopener noreferrer"). For regex reference see preg_match_all and for a jQuery UI option see slideToggle.

Recommended Answers

All 2 Replies

Hi,

I realy didnt understand what you are trying to do. The links has nothing there.

But it seems you have to use jquery too.

You may want to know about PHP through examples on net, or you may take help of another php programer.
The task here is to check out the forum database and see which field saves these links and which method displaya these links on the forum. There filtering out the link part is needed may be based on certain conditions and how to show the filtered links in two select boxes is the main part here and you may add some jquery/javascript to jump to the url.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.