deleting a word starting with a specific letter/character php

后端 未结 4 1396
名媛妹妹
名媛妹妹 2021-01-28 21:43

here is a simple example:

$correction = \"game\";
$text =\"Hello this is an example of a $word that starts with a $dollar sign\";
$text = str_replace(\"\\$word\"         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-28 21:50

    Use a regular expression and preg_replace

    $correction = "game";
    $text ="Hello this is an example of a \$word that starts with a \$dollar sign";
    $text = preg_replace('/\$\w+/', $correction, $text);
    print $text;
    

提交回复
热议问题