I guess my question is very simple, but I am new to php so I’m lost with this. Basically I would like to replace blanks (” “) by dashes (“-“) and let the anchor text in lowercase, since it will be used as part of the url.
Ex: the anchor text “William Shakespeare” will be converted to “william-shakespeare” to be inserted as part of the url.
<a href="http://site.com/biography/william-shakespeare">William Shakespeare</a>
If the text has only one word will be transformed to lowercase
Ex: “Shakespeare” will just be converted to “shakespeare”.
<a href="http://site.com/tag/shakespeare">Shakespeare</a>
Note: Text translated from the Portuguese language using GoogleTranslate.
No need for a regex. Just use str_replace & strtolower:
You should probably also urlencode it, in case you have some wonky characters in there: