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条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路