undefined offset when using php explode()

后端 未结 7 2016
闹比i
闹比i 2020-12-03 17:07

I\'ve written what I thought was a very simple use of the php explode() function to split a name into forename and surname:

// split name into f         


        
7条回答
  •  情书的邮戳
    2020-12-03 17:40

    this is because your fullname doesn't contain a space. You can use a simple trick to make sure the space is always where

     $split = explode(' ', "$fullname ");
    

    (note the space inside the quotes)

    BTW, you can use list() function to simplify your code

      list($first, $last) = explode(' ', "$fullname ");
    

提交回复
热议问题