简体   繁体   中英

how do i add a named anchor to my PHP dynamic link?

I need add a named anchor into this code:

<?
echo "<a href=\"reviews-mockup2.php?category=$category&amp;keyword=" . $_REQUEST['keyword'] . "&amp;nationalpage=";
?>

which currently looks like this in the page:

http://test.usfamilyguide.com/reviews-mockup2.php?category=&keyword=&nationalpage=1

I tried

<?
     echo "<a href=\"reviews-mockup2.php?category=$category&amp;keyword=" . $_REQUEST['keyword'] . "&amp;nationalpage=" . "#named-anchor";
?>

and got

http://test.usfamilyguide.com/reviews-mockup2.php?category=&keyword=&nationalpage=#named-anchor1

thanks!

Your anchor <a> tags seem to have an incorrect syntax. Refer to W3Schools .

Assuming, you are wanting it to jump to a particular section in a page; your solution should be something like this:

echo "<a href='reviews-mockup2.php?category={$category}&amp;keyword={$_REQUEST['keyword']}#named-anchor'>Your Anchor Name</a>";

What I did was: removed the nationalpage as I assumed thats what you were using to anchor to sections in the page, put all the PHP in curly braces {} and finally fixed your tag syntax as defined in the link I gave earlier. This should work to how you expect.

Any issues let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM