使用IF语句检查变量是否包含PHP中的£(磅)符号

时间:2017-09-26 08:00:17

标签: php

正如标题所说,我有一个变量,我存储来自客户的数据输入,如果数据包含一个英镑符号,那么这意味着他们输入了一个产品价格的英镑符号,如果不包含磅数签收,我需要确保添加它。

我知道PHP使用多字节字符。这是我正在检查的方式,但它不起作用:

if(($price[0] != "Â") && ($price[1] !="£")){
    $len = strlen($price);
    $char= '£';

    for($t = 0; $t<$len;$t++ ){
        $char .= $price[$t];
    }

    $price = $char;
}

我怎么能让这个工作?

3 个答案:

答案 0 :(得分:0)

嗨使用strpos()示例:

$a = '£100';
$b = '100';
if (strpos($a, '£') !== false) {
    echo 'a is price value';
}
if(strpos($b, '£') !== false)
{
    echo 'b is price value';
}

这可行吗

答案 1 :(得分:0)

结帐strpos

var id = ["title 1", "title 2", "title 3", "title 4", "title 5",];

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new ListView.builder(
          itemCount: id == null ? 0 : id.length,
          itemBuilder: (BuildContext context, int index) {
            return new GestureDetector( //You need to make my child interactive
              onTap: () => print(id[index]),
              child: new Card( //I am the clickable child
                child: new Column(
                  children: <Widget>[
                    //new Image.network(video[index]),
                    new Padding(padding: new EdgeInsets.all(3.0)),
                    new Text(id[index],
                      style: new TextStyle(fontWeight: FontWeight.bold,
                          color: Colors.black),
                    ),


                  ],
                ),),
            );
          }),
    );
  }

答案 2 :(得分:0)

您还应该尝试使用多字节字符串扩展,例如mb_strpos而不是strpos

相关问题