Avatar of ChrisTERiS
ChrisTERiS
 asked on

Remove illegal characters from SEO links

I'm using:
str_replace(" ", "-", $row['title']).'.html';

Open in new window

for building seo friendly urls, and it works fine. But there are some illegal characters eg % which are giving bad request.
Is there any function to remove all such illegal characters (I assume that there are other characters too).
I'm using PHP as server-side language.
PHP

Avatar of undefined
Last Comment
ChrisTERiS

8/22/2022 - Mon
stergium

Hello.
Why dont you try urlencode or htmlspecialchars or better yet a preg_replace?
ChrisTERiS

ASKER
Because I don't know which characters to add in the preg_replace.
ASKER CERTIFIED SOLUTION
ChrisTERiS

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Ray Paseur

Next time you have a question for EE, please give us some test data to work with.  You'll get faster and better results, I promise.  This article explains a little bit of the "why."
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7830-A-Quick-Tour-of-Test-Driven-Development.html
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ChrisTERiS

ASKER
Because the other one was very generic.