简体   繁体   中英

Same page Hyperlink with PHP

I would like to link to another part of a php page. So $x is a value I've pulled from an array that is a hyperlink.

echo "<a href='#{$x}'>{$x}</a>" . " "; 

However I am stuck in linking to the target id on the same page.

echo '<a id="$x">' . '<h2>'.strtoupper(str_replace("_", " ",($x))).' ' . 'offers'.'</h2>'.'</a>';

Sure when I hover over the link, it is passing the correct value of $x in the query string, but not linking to the because I am coding the target id part wrong.

Any help appreciated.

Volterony

If you want to visit a ID on on the page use href="#id"

echo '<a href="#'.$x.'">' . '<h2>'.strtoupper(str_replace("_", " ",($x))).' ' . 'offers'.'</h2>'.'</a>';

Improved Code

echo '<a href="#'.$x.'"><h2>'.strtoupper(str_replace("_", " ",($x))). 'offers </h2></a>';

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