-1

My url is likehttp://localhost/manishatutors/tutors-in-city/Crossing-Republik-tutor/

how could i get Crossing Republic using php

I used

<?php

list($a,$page_get) = explode("city/",$_SERVER['REQUEST_URI']);
    $array=explode("/",$page_get);
    $getCity1=remove_dash($array[0]);
    $p=$array[1];
        $get_city = implode('-',$getCity1);
print_r($get_city);
?>

but its giving Crossing republik tutor while I don't want tutor

4302836
  • 387
  • 1
  • 6
  • 14

2 Answers2

1

use explode function and take the last

$req_uris = explode('/',$_SERVER['REQUEST_URI']);
echo $req_uris[count($req_uris)-1];

and if you want you can replace dash with space

echo str_replace('-', ' ', $req_uris[count($req_uris)-1]);

EDIT

$url = 'http://localhost/manishatutors/tutors-in-city/Crossing-Republik-tutor/';

$exploded = array_values(array_filter(explode('/',$url)));
$last     = $req_uris[count($exploded)-1];

echo str_replace( '-', ' ', str_replace('tutor', '', $last) );

change $url with $_SERVER['REQUEST_URI']

Park Dong Gun
  • 114
  • 1
  • 4
0

You may try this

<?php

list($a,$val) = explode("city/",$_SERVER['REQUEST_URI']);
    $array=explode("/",$val);
    $val2=remove_dash($array[0]);
    $p=$array[1];
        $val3= implode('-',$val2);
print_r($val3);
?>

NEW EDITED ANSWER

list($a,$val) = explode("city/",$_SERVER['REQUEST_URI']);
    $array=explode("/",$val);
    $val2=$array[0];
    $p=$array[1];
        $val3= implode('-tutor',$val2);
print_r(remove_dash($val3[0]));
?>
4302836
  • 387
  • 1
  • 6
  • 14