PHP preg_replace xxx 以 $ 开头的任何数字
PHP preg_replace any number starting with $ by xxx
我想用 xxx 替换文本中每次出现的 $(任意数字)。例如,如果文本中出现 $923,则应为 xxx。
我尝试过的模式
$string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 0 remaining essentially unchanged. It was popularised in the 1960s with the release of required Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
$pattern = '/^$[0-9]+\.?[0-9]?[0-9]/i';
$pattern = '/($\[0-9]+)/';
$replacement = "xxx";
echo preg_replace($pattern, $replacement, $string);
试试这个 -
$s = "4 dsvsv 7 fsdgjfb";
echo preg_replace('/$\d+/', 'xxx', $s);
输出
xxx dsvsv xxx fsdgjfb
我想用 xxx 替换文本中每次出现的 $(任意数字)。例如,如果文本中出现 $923,则应为 xxx。
我尝试过的模式
$string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 0 remaining essentially unchanged. It was popularised in the 1960s with the release of required Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
$pattern = '/^$[0-9]+\.?[0-9]?[0-9]/i';
$pattern = '/($\[0-9]+)/';
$replacement = "xxx";
echo preg_replace($pattern, $replacement, $string);
试试这个 -
$s = "4 dsvsv 7 fsdgjfb";
echo preg_replace('/$\d+/', 'xxx', $s);
输出
xxx dsvsv xxx fsdgjfb