如何分隔字符串“JavaScript和PHP非常有趣!”在PHP中使用trim()?
每个人都必须在一个单独的行上。
他们都工作,除了“和”返回“d”和“是”返回“e”。有人可以帮忙吗?
<?php
$str12 = "JavaScript and PHP are so much fun!";
echo rtrim($str12,"and PHP are so much fun!");
echo "<br>";
echo trim($str12,"JavaScript PHP are so much fun!");
echo "<br>";
echo trim($str12,"JavaScript and are so much fun!");
echo "<br>";
echo trim($str12,"JavaScript and PHP so much fun!");
echo "<br>";
echo trim($str12,"JavaScript and PHP are much fun!");
echo "<br>";
echo trim($str12,"JavaScript and PHP are so fun!");
echo "<br>";
echo ltrim($str12,"JavaScript and PHP are so much");
?>
答案 0 :(得分:0)
可能你想这样做..检查这些代码....这可能对你有所帮助..
<?php
$str = "java and php are so much fun";
$pieces = explode(" ", $str);
foreach($pieces as $separate){
$separate;
echo str_replace($separate,'', $str);echo "<br>";
}
?>