0

Hey,
So I have a function to generate a slug URL, all the generated URLs must match a .htaccess rewriterule allowing only alpha-numerics, hyphens and underscores.
My question is; how do I remove ALL characters other than the allowed characters.
For reference, my URL rewrite is ([0-9a-zA-Z_-]+) -Sam

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by samarudge
1

assuming [0-9a-zA-Z_-] represents the set of allowed characters, and that $url contains the hyperlink you want to "clean", then try:

$url = preg_replace('#[^0-9a-zA-Z_-]#','',$url);
0

assuming [0-9a-zA-Z_-] represents the set of allowed characters, and that $url contains the hyperlink you want to "clean", then try:

$url = preg_replace('#[^0-9a-zA-Z_-]#','',$url);

Yup that worked, tnx

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.