deleting a word starting with a specific letter/character php

后端 未结 4 1467
名媛妹妹
名媛妹妹 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:56

    Something like so:

    preg_replace("/(\w*)$([a-z]+)/i", "$1$correction", $text);
    

    Note: I haven't tried it so my regex may be slightly flawed.

提交回复
热议问题