PHP中的Strpos问题 [英] Problem with Strpos In PHP

查看:94
本文介绍了PHP中的Strpos问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的函数,由于某种原因(可能是一个简单的函数),它对我不起作用,我想知道你们是否可以帮我解决问题.

I'm writing a simple function and for some reason(probably a simple one) it's not working for me and I was wondering if you guys could help me out.

function check_value($postID) 
    {
        $ID = $postID;
        $cookie = $_COOKIE['list_of_IDS'];
        $position = strpos($cookie,$ID);
        echo 'ID:'.$ID.'-Cookie:'.$cookie;
            if ($position !== false)
        {
            echo "ID is in the cookie";
        }
    }

在试图找出问题所在时,我将回显线放在If语句上方,以确保变量中确实有东西.

In trying to figure out what the problem was I put that echo line above the If Statement there to make sure there actually is stuff in the variables.

我的问题是IF语句永远不会打印出来.

My problem is that the IF statement never prints out.

A $postID是数字123123.

$cookie字符串通常类似于123123.23422.234234.2342342.234234

感谢您的帮助!

推荐答案

Strpos不能与int一起使用,因此您需要将ID转换为字符串.试试这个:

Strpos won't work with an int, so you need to cast the ID to a string. Try this:

$ID = (string)$postID;

这篇关于PHP中的Strpos问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆