我正在尝试使用preg_replace()
函数加粗特定的字符串内容。 $()
字符串成功加粗。
<?php
$text=preg_replace("/$()/","<b>$()</b>","$(), you can");
echo $text;
?>
但是一旦我在括号内添加了一些单词,函数就会停止工作。尽管如此,该函数也没有抛出任何错误。
<?php
$text=preg_replace("/$(abc)/","<b>$(abc)</b>","$(abc), you can");
echo $text;
?>
有人可以解释一下吗?提前谢谢。
答案 0 :(得分:2)
第一个正则表达式"worked",因为它匹配输入末尾的空字符串,并替换为 import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class MoveFileExample
{
public static void main(String[] args)
{
InputStream inStream = null;
OutputStream outStream = null;
try{
File afile =new File("C:\\folderA\\Afile.txt");
File bfile =new File("C:\\folderB\\Afile.txt");
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
byte[] buffer = new byte[1024];
int length;
//copy the file content in bytes
while ((length = inStream.read(buffer)) > 0){
outStream.write(buffer, 0, length);
}
inStream.close();
outStream.close();
//delete the original file
afile.delete();
System.out.println("File is copied successful!");
}catch(IOException e){
e.printStackTrace();
}
}
}
。
您需要转义特殊符号:
<b>$()</b>
请参阅IDEONE demo
'/\$\(abc\)/'
输出:$text=preg_replace("/\\$\\(abc\\)/","<b>$(abc)</b>","In place of $(abc), you can");