Search code examples
phpstrstr

strstr() don't work in PHP


I have this code in PHP with that uses the function, strstr():

$conversation = strstr($bash, '_');
$pseudo = strrchr($bash, '_');
//On ajoute les balises html au pseudo et a la conversation
$cherche = array($pseudo, $conversation);
$remplace = array("'<span class=\"pseudo\">' , $pseudo , '</span>'",
                  "'<span class=\"pseudo\">' , $conversation , '</span><br />'");
str_replace($cherche, $remplace , $bash);
echo $bash;

However, echo function display $bash does not display any error message.


Solution

  • str_replace() RETURNS the modified string, it does not do an in-place change.

    $new_bash = str_replace($cherche, $remplace, $bash);