1
I need to get the headline of a story and run it through the URL. To do this, I want to search the title in the database and replace each blank space between a word and another with a hyphen. For example: "Newstest" would be "Newstest".
I tried to:
$titulo_novo = preg_replace('<\W+>', "-", $titulo);
//$titulo é o titulo vindo do banco de dados
What have you tried? Do you have any code you’d like to show to help solve your problem? Increase the content of the question and you will get more specific answers ;)
– João Victor Gomes Moreira
I tried: $titulo_novo = preg_replace('< W+>', "-", $titulo); //$titulo is the title coming from the database.
– Developer1903
Edit the question by adding this new friend info
– João Victor Gomes Moreira
try like this
$titulo_novo = preg_replace('/[ -]+/' , '-' , $titulo);
– João Victor Gomes Moreira
I got it. It only generated one error: accented characters (ã, ó, etc.) need to be normal, for example, will be replaced by ; ion by cao...
– Developer1903