dskzap8756 2013-12-28 17:44
浏览 37
已采纳

Preg_replace不使用捕获参数和<

When I add the less than "<" symbol

$str = 'test';
$str = preg_replace('@(.*)@isu', '<$1', $str);
echo $str; // outputs ""

It should output <test, but instead outputs nothing.

It works fine when I don't add the character.

$str = 'test';
$str = preg_replace('@(.*)@isu', '$1', $str);
echo $str; // outputs "test"

I tried escaping it

$str = 'test';
$str = preg_replace('@(.*)@isu', '<\\\\$1', $str);
echo $str; // outputs "<\test"

I was unable to find anything about this in the php manual while google just spits out unrelated SO questions.

I would like to know why this does not work?

PHP 5.4.22

  • 写回答

3条回答 默认 最新

  • duanlu8613 2013-12-28 17:57
    关注

    I think you are checking the outputs from the browser. That's why its doing such behaviour. From the console it works perfectly. So, I believe you'll find everything when you view the source of html from browser.

    Also, you can replace the < with &lt;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要