It's relatively easy to make URL safe strings for use by mod_rewrite. Let's use the example that you have a form that adds a new blog post to your site. When the user submits this form, you want to generate a URL safe string (based on the title of the blog post) for mod_rewrite to use. This little snippet will show you how this can be achieved in one line of code in PHP.
The following function shows just how easy it is to generate a URL safe string for mod_rewrite. I've even included a demo of this code below.
That's all there is to it! To break it down a little, you could have written it as per the following:
please…
how I can correct this line of script?
$string = preg_replace (' /[^a-z0-9] +/' , ' - ' , $string);
because the accepted language Portuguese-Brazilian caracter in the words, and the line this removing the letter and the accent:
original example: Lúcio usa clichês e evita até mesmo falar sobre os rivais na Copa
example script: l-cio-usa-clich-s-e-evita-at-mesmo-falar-sobre-os-rivais-na-copa-1.html
thank you
Hello Joao…
If you modify the line of code to include this:
$string = preg_replace (' /[^a-z0-9úêé] +/' , ' - ' , $string);
That should fix the mod_rewrite for you. You would, of course, have to add in the rest of the native characters for Portuguese-Brazilian, as I have done for the ú, ê and é.