我需要使用trim()分隔一个字符串

时间:2016-02-24 01:27:18

标签: php

如何分隔字符串“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");
?>

1 个答案:

答案 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>";
}

?>