PHP code example of boeki / migration-tool

1. Go to this page and download the library: Download boeki/migration-tool library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

boeki / migration-tool example snippets


	 $matches = [];
		foreach($firstnames as $firstname) {
			$pos = strpos(strtolower($value), strtolower($firstname));

			if($pos !== false) {
				$matches[] = array("pos" => $pos, "firstname" => $firstname);
			}
		}

	$best_matche = array("pos" => null, "firstname" => "");
	foreach($matches as $matche) {
		if(strlen($best_matche["firstname"]) < strlen($matche["firstname"])) 
			$best_matche = $matche;
	}

	$lastname = null;
	$lastname_is_before = $best_matche["pos"] > strlen($value) - ($best_matche["pos"] + strlen($best_matche["firstname"]));

	if($lastname_is_before)
		$lastname = substr($value, 0, $best_matche["pos"]);
	else 
		$lastname = substr($value, $best_matche["pos"] + strlen($best_matche["firstname"]), strlen($value) - 1);

$name = "JAMESSTANDBRIDGE";
var_dump(NameRectifier::SEPARATE($name));

$name = "STANDBRIDGEJames";
var_dump(NameRectifier::SEPARATE($name));

$name = "STANDBRIDGEJamesDEEGYZ";
var_dump(NameRectifier::SEPARATE($name));

	$matches = [];
	foreach($firstnames as $firstname) {
		for($i = 0; $i < count($mapping); $i++) {
			if(strtolower($mapping[$i]['part']) == strtolower($firstname))	
				$mapping[$i]['isFirstname'] = true;
		}
	}

	$thereIsALastname = false;
	$thereIsAFirstname = false;
	foreach($mapping as $map) {
		if($map['isFirstname'] === false) 
			$thereIsALastname = true;
		else
			$thereIsAFirstname = true;
	}

	//if no firstname, we set last slug to firstname
	if(!$thereIsAFirstname)
		$mapping[count($mapping) - 1]['isFirstname'] = true;

	if($thereIsALastname) {
		//...
	} else {
		foreach($mapping as $key => $map) {
			if($key === 0 && count($mapping) > 1) 
				$lastnames .= ucfirst(strtolower($map['part']))." ";
			else
				$firstnames .= ucfirst(strtolower($map['part']))." ";
		}
	}

	$firstnames = "";
	$lastnames = "";
	$lastnameBarrier = false;
	$composedNameBarrier = false;

	if($thereIsALastname) {
		foreach($mapping as $map) {
			if($map['isFirstname'] && !$lastnameBarrier && !$composedNameBarrier) {

				$firstnames .= ucfirst(strtolower($map['part']))." ";
				$isComposed = strpos($map['part'], "-") !== false;
				if($isComposed)
					$composedNameBarrier = true;
			}
			else {
				$lastnames .= ucfirst(strtolower($map['part']))." ";
				if(strlen($firstnames) > 0)
					$lastnameBarrier = true;
			}
		}
	}

$name = "STANDBRIDGE James";
var_dump(NameRectifier::SEPARATE($name));

$name = "Jean-baptiste lucas francois";
var_dump(NameRectifier::SEPARATE($name));

$name = "Standbridge Ciron";
var_dump(NameRectifier::SEPARATE($name));
bash
array(2) {
  ["firstname"]=>
  string(5) "James"
  ["lastname"]=>
  string(11) "Standbridge"
}
bash
array(2) {
  ["firstname"]=>
  string(5) "James"
  ["lastname"]=>
  string(11) "Standbridge"
}
bash
array(2) {
  ["firstname"]=>
  string(5) "James"
  ["lastname"]=>
  string(11) "Standbridge"
}
bash
array(2) {
  ["firstname"]=>
  string(5) "James"
  ["lastname"]=>
  string(11) "Standbridge"
}
bash
array(2) {
  ["firstname"]=>
  string(5) "Ciron"
  ["lastname"]=>
  string(11) "Standbridge"
}