【发布时间】:2018-03-27 11:36:32
【问题描述】:
我需要在带有length >= 6 的字符串中查找单词,并将第6 个字符之后的任何字符替换为*。
似乎很困惑如何遍历 $parts 数组来查找这 6 个字母的单词。
有人可以帮忙吗?
$a = 'The game is set in "The City", a dark fantasy world inspired by
Victorian, Gothic, and steampunk aesthetics. Players control Garrett, a
master thief who embarks on several missions focusing on stealing from the
rich. Players may approach levels in a variety of different ways; players
can choose the action oriented and lethal approach, where players will
disable or kill enemies on their way to their destination, using knives and
takedowns, or opt for the non-lethal stealthy approach, where players
minimize interaction with NPCs and the environment in order to avoid
detection. Players also may choose which path to take to their destination,
as each location contains several branching paths.';
$length = 6;
$parts = explode(' ',$a);
然后
for ($i = 0; $i == $length; $i++){
echo str_replace($parts, '*', $a);
}
【问题讨论】:
-
这听起来像是功课
-
你在explode.pass
$a中传递$x而不是$a到explode函数中。 -
@Awaisfiaz 哦,是的。谢谢。完成
-
@NigelRen 很明显。一段时间以来,我一直在尝试自己提出解决方案。出于沮丧而询问并处于死胡同。有什么问题吗?
-
很难获得答案可能远远超出您所学的范围,因此很明显这不是您自己的工作。无论如何,祝你的课程好运:)