dsxi70423 2011-12-02 16:51
浏览 28
已采纳

php替换字符串错误

I am trying to delete a string from a string, but the result of strstr is not finding the string. I will try to be as clear as I can here....

The problem is strpos() is not finding $deletTabHTML. I have alerted it in ajax and it is exactly the same as a line in the commonHTML, but obviously it isn't for some reason I cannot figure out. I am assuming I am missing something 'invisible'? My script works if I hardcode the html to be deleted, so the overall script works.

here is the php:

$commonHTML = file_get_contents($url);
if (!empty($_POST['action']) && $_POST['action'] == 'deleteTab') {
    $deletTabHTML = trim($_POST['theHTM']);
    if(strpos($commonHTML, $deletTabHTML) !== false) {
        $is_deleted="deleted";
    }else{
        $is_deleted="NOT deleted, ERROR:".$deletTabHTML;
    }
    echo '{"is_deleted":"' . $is_deleted . '"}';
    return;
}

MORE INFO: jQuery is getting an element from the dom and sending it to a php script which is opening a file and deleting the element:

<li id="contact"><a href="#contact" rel="ajax">Contact</a></li>

The data returned to ajax is:

<li id="contact"><a href="#contact" rel="ajax">Contact</a></li>

but for some reason it is not finding it. Thos were copied and pasted from the actual file and a javascript alert. They look exactly the same.

I hope that is enough info.

  • 写回答

2条回答 默认 最新

  • dongqu2863 2011-12-02 17:05
    关注

    strpos is case sensitive

    Try

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

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c