简体   繁体   中英

How do I successfully add %s to my a href link?

I've had a website for almost 10 years which lists my old radio shows from a MySQL database. Just recently the page stopped working, which I imagine is because most of the code has become outdated. I've tried updating the code, and everything works fine until I add the "%s" into the a href tag to pull up the actual audio file.

I need the link to say "http://www.hauntedamericaradio.com/audio/Episode%s.mp3"

Take out the %s and the page shows fine, put it back in and all the text on the page disappears.

Here's the PHP part of my page:

<?php 
$servername = "localhost";
$username = "*******";
$password = "*******";
$database = "*******";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
  
 // Request the id of all the stories 
 $result = @mysqli_query($conn, "SELECT * FROM shows ORDER BY ID DESC"); 
 if (!$result) { 
   echo("<p>Error performing query: " . mysql_error() . "</p>"); 
   exit();
   
 } 
 // Display the newest story 
 while ( $row = mysqli_fetch_array($result, MYSQLI_BOTH) ) { 
     printf("<tr><td align=justify valign=top><img src=images/%s border=0 bordercolor=#000000 
width=150 align=left hspace=5 vspace=5><p align=center><font color=#F9CF91 face=verdana 
size=+1>Episode %s - %s</font></p>",$row["Photo"], $row["Episode"], $row["Headline"]);
    printf("<p align=justify><font color=#F9CF91 face=verdana 
size=-1>%s</font>",$row["Description"]);
    printf("<p align=center><font color=#F9CF91 face=verdana size=+1><a 
href=http://www.hauntedamericaradio.com/audio/Episode.mp3>Click To Listen</a></font></p></TD> 
</TR><TR><TD><HR width=99% color=black></TD></TR>", $row["Link"]);

} 

?>

This is what the page looks like when it's working (minus the broken audio links):

http://www.hauntedamericaradio.com/btrarchives.php

Here's what it looks like with the %s in the link:

http://www.hauntedamericaradio.com/btrarchives1.php

Thanks guys for any help you can give!

Usually, you have to encode those characters in the URL

for % we use %25 ... space for instance is %20

It is based on the HEX code from the ascii table

So your URL will be http://www.hauntedamericaradio.com/audio/Episode%25s.mp3

you can find it all here https://ascii.cl/htmlcodes.htm

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