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

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);

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.