Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3451950
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:12:03+00:00 2026-05-18T09:12:03+00:00

How can I check if an anchor tag is empty with PHP or preg_match

  • 0

How can I check if an anchor tag is empty with PHP or preg_match or JQuery? For example if an achor tag looks like: <a href="some_url"></a> I want to skip over it.

I am trying to add database functionality to Superfish menu but in Google Chrome I get empty anchor tags in the sub-menus. In all other browsers it works fine.

I can’t figure out what the problem is so I thought if I could not output empty anchors it might work.

Can you help?

Thank you!

<?php
//---------------------------------------------------------------
// INCLUDE DB CONNECTION
//---------------------------------------------------------------
require_once(ROOT_PATH.'connections/mysql.php');
require_once(ROOT_PATH.'controls/menu/error_messages.php');

//---------------------------------------------------------------
// GET MENU FROM DB
//---------------------------------------------------------------
$get_menu = mysqli_query($conn, "SELECT MenuId, Url, Target, Label, Title, Description, ParentId, OrdinalPosition, IsEnabled FROM menu WHERE (IsEnabled = 1) ORDER BY ParentId, OrdinalPosition, Label")
or die($dataaccess_error);

if(mysqli_num_rows($get_menu) > 0)
{
    // loop through menu items
    while ($menu_item = mysqli_fetch_assoc($get_menu))
    {
        $menu_data['MenuItem'][$menu_item['MenuId']] = $menu_item;
        $menu_data['MenuParent'][$menu_item['ParentId']][] = $menu_item['MenuId'];
    } 
}
else
{
    echo $no_menu_items_error;
}

//---------------------------------------------------------------
// BUILD MENU FUNCTION FOR SUPERFISH
//---------------------------------------------------------------
function HorizMenu($parent_id, $menu_data)
{
    $html = '';

    if (isset($menu_data['MenuParent'][$parent_id]))
    {
        $html = '<ul class="sf-menu">';
        foreach ($menu_data['MenuParent'][$parent_id] as $itemId)
        {
            // menu variables
            $url = $menu_data['MenuItem'][$itemId]['Url'];
            $target = $menu_data['MenuItem'][$itemId]['Target'];
            $title = $menu_data['MenuItem'][$itemId]['Title'];
            $label = $menu_data['MenuItem'][$itemId]['Label'];

            $html .= '<li class="current"><a href="'.$url.'" target="'.$target.'" title="'.$title.'">'.$label;

            // find childitems recursively
            $html .= HorizMenu($itemId, $menu_data);

            $html .= '</a></li>';
        }
        $html .= '</ul>';
    }

    return $html;
}

// output the menu
echo HorizMenu(0, $menu_data); 
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:12:04+00:00Added an answer on May 18, 2026 at 9:12 am

    This is something that should be taken care of with JavaScript (JQuery). You can use JQuery’s “each” method as follows:

    $('a').each(function(index) {
       if( $(this).attr('href') == [something] ) {
          //Do Something
       }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.