noptin_split_subscriber_name( $name )

Converts a name field into the first and last name


Description Description

Simple Function, Using Regex (word char and hyphens) It makes the assumption the last name will be a single word. Makes no assumption about middle names, that all just gets grouped into first name. You could use it again, on the "first name" result to get the first and middle though.


Top ↑

Source Source

File: includes/subscriber.php

function noptin_split_subscriber_name( $name ) {

	$name       = trim( $name );
	$last_name  = ( strpos( $name, ' ' ) === false ) ? '' : preg_replace( '#.*\s([\w-]*)$#', '$1', $name );
	$first_name = trim( preg_replace( '#' . $last_name . '#', '', $name ) );
	return array( $first_name, $last_name );

}


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.0.5Introduced.

Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation