我试图分析文本,然后当我看到":)"我将用图像的路径替换它有没有办法让这发生?
提前致谢..
$text = "This would be fun :)"
Run Code Online (Sandbox Code Playgroud)
想要的结果="这将是有趣的图像路径在这里 "
因此,我将看到图像的路径显示为笑脸而不是":)"
$text = "This would be fun :)"
$newtext = str_replace(":)", "<img src='images/smiley.png'>", $text);
Run Code Online (Sandbox Code Playgroud)
从php.net下面的多个替换查找示例
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
// Provides Result: Hll Wrld f PHP
Run Code Online (Sandbox Code Playgroud)