Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $string1 = 'http://2.2.2.2/~machinehost/deployment_folder/';
- $string2 = '/~machinehost/deployment_folder/users/bob/settings';
- $split = str_split($string2);
- $needle = '';
- $matches = array();
- foreach($split as $needleAppend) {
- if (!empty($needle)) {
- if (strpos($string1, $needle) === false) {
- $needle = '';
- } else {
- $matches[] = $needle;
- }
- }
- $needle = empty($needle) ? $needleAppend : $needle . $needleAppend;
- }
- function sortByLength($a,$b) {
- return strlen($b)-strlen($a);
- }
- usort($matches, 'sortByLength');
- $largestString = array_shift($matches);
- $remainder = substr($string2, strlen($largestString));
- var_dump($remainder);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement