Calling a PHP function from an <a> tag?

I’m new to PHP and was wondering if it’s possible to call a PHP function from an <a> tag in HTML. Below is my code that I’m using.

            <div class="menuBar">
                <nav>
                    <label class="sidebar"><a class="menu" href="<?php menuCheck(1); ?>">Summary</a></label>
                    <label class="sidebar"><a class="menu" href="<?php menuCheck(2); ?>">Technical Skills</a></label>
                    <label class="sidebar"><a class="menu" href="<?php menuCheck(3); ?>">Experience</a></label>
                    <label class="sidebar"><a class="menu" href="<?php menuCheck(4); ?>">Education</a></label>
                    <label class="sidebar"><a class="menu" href="<?php menuCheck(5); ?>">Certifications</a></label>
                    <label class="sidebar"><a class="menu" href="<?php menuCheck(6); ?>">Contact Me</a></label>
                </nav>
            </div>

The above code is not working.

Please help!

Thank you

No, that’s not the way things work.
Functions are not called while viewing a page, everything happens prior to the page being delivered to the browser. This is a fundamental of server-side scripting.

The <a> may have a URL to a PHP script you want to run.
But unless menuCheck() echos a URL, this is not going to work.

Maybe if you explain what your objective is, someone may offer a solution.

1 Like

Probably need an echo in there:

href="<?php echo menuCheck(1); ?>"
1 Like

What do the 1, 2, 3, etc stand for?

Maybe you know now, but would you still know in a year? in 5 years?

What if you ever want to add a menu item between 2 and 3? Would everything shift?

In short, don’t use magic numbers, you’ll regret it later.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.