doujinai2183 2012-11-08 17:21
浏览 11
已采纳

CodeIgniter:字符串是否包含函数?

Form on Page:

<div>
<?php echo form_open('add/player');
    echo form_label('First Name','playerFirstName');
    echo form_input('playerFirstName','test');
    echo "<br />";
    echo form_label('Last Name','playerLastName');
    echo form_input('playerLastName','test');
    echo "<br />";
    echo form_submit('addPlayer','Add Player');
    echo form_close(); ?>
</div>

Called Controller:

class Add extends CI_Controller
{
    public function index()
    {
        $this->load->view('header');
        $this->load->view('add');
        $this->load->view('footer');
    }

    public function Player()
    {
        if(strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
        {
            if(basename($_SERVER['HTTP_REFERER']) == basename($_SERVER['PHP_SELF']))
            {
                $this->load->model('players');
                $returnMessage = $this->players->add_player($this->input->post('playerFirstName'), $this->input-post('playerLastName'));
            }
        }
        $this->load->view('header');
        $this->load->view('addplayer');
        $this->load->view('footer');
    }
}

I'm a very green novice when it comes to PHP, CodeIgniter and MySQL (or web coding in general), so if you see any suggestions, please don't hesitate to make them (though the credit will be given to the one who answers my question, not makes my code work the best). However, as to my question, is there a way to see if a string is within another string? My $returnMessage, if successful will have the word successfully in it. What I want to do is if the player is not added, I want to reload the values from the form and put them back. Here's where it gets tricky.

The names are saved in table people_names. In the players table, I save the nameid that is associated with that name in the people_names table. In my add_player function, I check to see if the names are in the table, if they aren't I add them, then I add the player to the players table with the appropriate ids. Because of this, I'm not sure form_validation would be able to be used or not. If it were, please let me know.

So what I want to do is check the $returnMessage and if it doesn't contain successfully, then I want to add the values back to the fields. However, I'm not finding a function where I can see if a string is inside of another string. I see string compares and substring functions, but no string contains. Any ideas? Thanks.

  • 写回答

2条回答 默认 最新

  • dsfb20227 2012-11-08 17:24
    关注

    Use native PHP's strpos: http://php.net/manual/en/function.strpos.php

    Cheers

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

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀