php - Best practices for URL with space and special characters -
i'm modifying small web application. web application allow users enter / specify category themselves. noticed in database, there's plenty of category contain spaces , special characters, example cakes & cupcakes.
on front-end, database shows user defined categories in form of url links , user can click on them further see what's in category.
the front-end category links encoded using rawurlencode function , looks this.
./show.php?category=<?php echo rawurlencode($e['category']); ?>
and on back-end, function get
url , decode before it's being sent database querying.
$category = rawurldecode(htmlspecialchars_decode($category));
it works fine seems 'last-minute' , 'unsophisticated'.
as such i'm wondering, best practice in php url special characters , spaces?
thank in advance.
i prefer use "slug" method. "slugify" strings , use slug in url.
http://sourcecookbook.com/en/recipes/8/function-to-slugify-strings-in-php
you'll need add column database slug, can represent user input fields in url , make them readable. "function-to-slugify-strings-in-php" slug looked "function slugify strings in php".
Comments
Post a Comment