2
I’m trying to treat a string with the function str_replace
but I wanted to insert a <span>
before the word treated, as in the example below:
$entrada = array("//");
$tratamento = array("<span class='comentario'>//</span>");
$saida = str_replace($entrada, $tratamento, $mensagem);
My doubt:
It is possible to do this with the function str_replace
, or only with regular expressions, if it is only with ER’s I would like you to give me examples.
I wish after I did that I would return something like:
<span class='comentario'>//</span>
Valeu Galera!
Do you want to turn a predetermined word into span, or do you want everything between // and end of line between span? Whether the text will vary outside of code control, only ER itself, or a combination of initial string location and final string, and substitution, which can be much faster than regex/ER.
– Bacco
@Bacco I want everything between // and end of the line between in span, how can I do this?
– Odair