undefined offset when using php explode()

后端 未结 7 2015
闹比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:44

    This could be due the fact that $fullname did not contain a space character.

    This example should fix your problem w/o displaying this notice:

    $split = explode(' ', $fullname, 2);
    $first = @$split[0];
    $last = @$split[1];
    

    Now if $fullname is "musoNic80" you won't get a notice message.

    Note the use of "@" characters.

    HTH Elias

提交回复
热议问题