Sarah
Sarah

Reputation: 415

how to echo when user click on anchor tag in php?

I want to echo on dynamic url but when I use ? then it is working and when I use / then the url changing but nothing echo out.

<?php
 $pages = array("story1", "story2", "story3", "story4");

 if(isset($_GET['stroy2'])) { 
      echo "You are reading Story 2!";
 }

 if(isset($_GET['stroy3'])) {
      echo "You are reading Story 3!";
 }
 ?>

<html>
<body>
  <form action="kids.php" method="post">

    // $i=2; here and below line is not working. This is the problem.
     <a href="http://www.abcd.com/kids.php/<?php echo $pages[$i];?>" <?php echo $pages[$i];?></a>
  </form> 
 </body>
 </html>

The line works when I use question mark "?" after kids.php? and the content is also changing:

<a href="http://www.abcd.com/kids.php?<?php echo $pages[$i];?>" <?php echo $pages[$i];?></a>

My problem is that I want to use / instead of question mark ?

Upvotes: 0

Views: 261

Answers (1)

rpm192
rpm192

Reputation: 2454

You're looking for something that is called pretty URLs.

For example, if I have the page http://localhost/index.php?user=1 and want to turn it into http://localhost/users/1 you could add these lines to your .htaccess file.

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^user/(.*)$ ./index.php?user=$1

This stackoverflow question will most likely help you.

Upvotes: 3

Related Questions