我有问题,str_replace不能替换倒数第二个单词...第一个单词正在工作然后第二个到最后一个不在数组中工作..我尝试在"chat.php?"中输入消息"ducker apple banana chicken"? message ="然后变成这样:
输出:
"***er apple banana chicken"
badwords.txt:
duck;
apple;
banana;
chicken;
water;
Run Code Online (Sandbox Code Playgroud)
chat.php
$censoredfilter = file("badwords.txt");
$censoredfilter = implode("\n", $censoredfilter);
$censoredfilter = explode(";", $censoredfilter);
$message = $_GET['message'];
for($i = 0; $i<sizeof($censoredfilter);$i++)
{
$message = str_replace($censoredfilter[$i], "***", $message);
}
Run Code Online (Sandbox Code Playgroud) 简单的希望,是否有一种方法可以将strtolower和str_replace一起使用.目前我正在改变一个变量的值并单独声明它,并认为如果我能一起做这个会更有效吗?
$afixteam = str_replace(" ","-",$fixData['ateam_name']);
$afixteamlink = strtolower($afixteam);
Run Code Online (Sandbox Code Playgroud)
谢谢.
您好我试图使用php str_replace将所有单引号设为双引号但是无论我做什么,它似乎都不起作用,建议
$page = str_replace("/'/", '/"/', $page);
Run Code Online (Sandbox Code Playgroud) 我对PHP很陌生,所以请耐心等待.
我有一个带有表情符号的数组,我想用正确的图像替换表情符号文本,所有这些都在for循环中.所以我正在尝试使用我的文本变量并执行str_replace,但我不确定如何在表情符号被更改后显示文本.
这是我的代码:
$content = ":D Here is a sample sentence for this example :)";
$emotes = array(
[":)","<img class='emoticon' src='smile.png'>"],
[":D","<img class='emoticon' src='grin.png'>"],
);
for($i=0;$i<count($emotes);$i++) {
$contentWithEmotes = str_replace($emotes[$i][0], $emotes[$i][1], $content);
}
print $contentWithEmotes;
Run Code Online (Sandbox Code Playgroud)
这个问题是它只显示数组中的最后一个图像,当我希望它显示它们时.我该如何使用正确的图像显示内容?
在此先感谢您的帮助.
请帮助我,我已经陷入这些问题几天了.我有一个Web表单,将在asp.net中付款,语言是C#.
文本框用于接受来自用户的货币金额.我的要求是,如果用户输入例如75,则在_TextChanged事件中它将切换到75.00.我得到了这部分工作.但我的代码没有检查位置后的三个字符.并删除多余的零.我的问题:1.如果输入超过小数点后的两位数,如何删除多余的零?2.如果用户未在文本框中输入任何数字,我该怎么办?我试过,我只是得到错误或它弄乱了整个代码.
protected void txtAmount_TextChanged(object sender, EventArgs e)
{
string textBoxData = txtAmount.Text;
int textLength = textBoxData.Length;
int position = txtAmountToPay.Text.IndexOf("."); //Position is the decimal
if (position == -1)
{
textBoxData = textBoxData + ".50"; // when you enter 75 you get 75.50
}
if (position == textLength -2 )
{
textBoxData = textBoxData + "4"; // when you enter 75.0 you get 75.04
}
if (position == textLength -1)
{
textBoxData = textBoxData + "30"; // when you enter …Run Code Online (Sandbox Code Playgroud) 我试图用字符串中的"is not"替换"is"但是有一个例外,它不应该替换驻留在其他单词中的"is".
例
"This is an ant" --> "This is not an ant" [CORRECT]
"This is an ant" --> "This not is not an ant" [INCORRECT]
Run Code Online (Sandbox Code Playgroud)
到目前为止,我所做的是
String result = str.replaceAll("([^a-zA-Z0-9])is([^a-zA-Z0-9])","$1is not$2");
result = result.replaceAll("^is([^a-zA-Z0-9])","is not$1");
result = result.replaceAll("([^a-zA-Z0-9])is$","$1is not");
result = result.replaceAll("^is$","is not");
Run Code Online (Sandbox Code Playgroud)
但我认为只有一个正则表达式是可能的,但我无法弄明白.可能吗?
嗨,我需要在span标签中包装字符串的最后一个字母,我怎么能在PHP中执行此操作?
例如:
$string = 'Get on the roller coaster';
Run Code Online (Sandbox Code Playgroud)
应输出:
'Get on the roller coaste<span>r</span>'
Run Code Online (Sandbox Code Playgroud) <?php
echo "I'm currently listening to</a> <a href='http://last.fm/artist/" . str_replace(" ","+",$artist) . "/_/" . str_replace(" ","+",$currenttrack) . "'>" . $currenttrack . "</a>";
?>
Run Code Online (Sandbox Code Playgroud)
以上是我的代码.我想str_replace()再次使用$artist并$currenttrack喜欢:
str_replace("'","%27",$artist) 和 str_replace("'","%27",$currenttrack)
因为撇号没有正确地通过我的代码混乱,但是当我首先使用空格时,它已经通过并且不会再次改变.
我能做什么?
我在Eclipse中开发的一个刽子手游戏的代码片段如下:
String secret = "apple";
String str = "-----"
for (int i = 0; i < 5; i++) {
if (letter == secret.charAt(i)){
str = str.replace(str.charAt(i), letter);
}
}
System.out.println(str);
Run Code Online (Sandbox Code Playgroud)
不幸的是,这是打印出来的
aaaaa
Run Code Online (Sandbox Code Playgroud)
代替
a----
Run Code Online (Sandbox Code Playgroud)
我怎么能这样工作?
我有一个字符串:
a = '3+7-9'
Run Code Online (Sandbox Code Playgroud)
我需要反转'+'成'-'和'-'成'+',以获得
a = '3-7+9'
Run Code Online (Sandbox Code Playgroud)
使用python-3.x而不乘法的正确方法是什么* -1?