undefined offset when using php explode()

后端 未结 7 2012
闹比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:31

    BTW, that algorithm won't work all the time. Think about two-word Latina or Italian surnames names like "De Castro", "Dela Cruz", "La Rosa", etc. Split will return 3 instead of 2 words:

    Array {
      [0] => 'Pedro'
      [1] => 'De'
      [1] => 'Castro'
    }
    

    You'll end up with messages like "Welcome back Ana De" or "Editing Profile of Monsour La".

    Same thing will happen for two-word names like "Anne Marie Miller", "William Howard Taft", etc.

    Just a tip.

提交回复
热议问题