dongyao8698 2011-02-24 00:12
浏览 80
已采纳

PHP preg_replace()问题

I was wondering if you could help.

I have the line:

$desc = preg_replace("/#\d{1,3}%/", "<b>$0</b>", $desc);

Where $desc is a tweet. Im hoping to recognise hash tags with a percentage. Such as:

#100% or #25% or #1%

However the string is not getting either matched or replaced. If you could help it would be greatly appreciated.

Example:

$desc = "testing #ugp 123 fb #75% #1% #100%. (Twitter@Feb 23, 2011 6:06 PM)";
$desc = preg_replace("/#\d{1,3}%/", "<b>$0</b>", $desc);
echo $desc;

Expected output would have the 3 matching tags to be wrapped in tags, However output does not change from the original

Cheers

  • 写回答

2条回答 默认 最新

  • dongwang788787 2011-02-24 00:23
    关注

    works for me:

    $desc = "testing #ugp 123 fb #75% #1% #100%. (Twitter@Feb 23, 2011 6:06 PM)";
    $desc = preg_replace("/#\d{1,3}%/", "<b>$0</b>", $desc);
    echo $desc; //testing #ugp 123 fb <b>#75%</b> <b>#1%</b> <b>#100%</b>. (Twitter@Feb 23, 2011 6:06 PM)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积