I’m working on a site that displays pages focusing on animals. The value ursus-maritimus in my database matches the URL mysite/life/ursus-maritmus (polar bear).
But I also want to display the same page using common names. So I have another database table that contains the value ‘polar bear’ Using str_replace, I can now display the same page at mysite/life/polar-bear
The problem is apostrophes and accents. For example, consider the database value Grevy’s zebra. [Note: I don’t have stick figure apostrophes in my database. That should look like Grevy&-#-8-2-1-7-;s without the hyphens] I want a “clean” URL that looks like this: grevys-zebra.
So how do I tell my query to ignore apostrophes, accents, etc. in my database values?
This is what my code looks like right now:
$CommonURL = str_replace('-', ' ', $MyURL);
$sql = "SELECT SUM(num) as num FROM (
SELECT COUNT(Name_Common) AS num FROM gz_names_kingclass WHERE Name_Common = :CommonURL
UNION ALL
SELECT COUNT(Name_Common) AS num FROM gz_names_species_mammals WHERE Name_Common = :CommonURL
) AS X";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':CommonURL',$CommonURL,PDO::PARAM_STR);
$stmt->execute();
$Total = $stmt->fetch();
Thanks!