Skip to content
Advertisement

How to remove first few letter and print the last title in php

I have got the permalink and the page title. I need to remove the only permalink and print the title in using PHP. Here is code: $string = "http://example.com/blog/PageTitle"

From here remove the http://example.com/blog/ and print only PageTitle

I tried it:

$string = 'http://example.com/blog/PageTitle';
$remove_text = 'http://example.com/blog/'
$count = strlen($remove_text)
echo substr($string, $count);

N.B: my $string and pageTitle are changable like http://example.com/about/PageTitle, http://example.com/contact/PageTitle2 etc.

Advertisement

Answer

Try this

$string = strrev($string);
$str_arr = explode ("/", $string);
$pageTitle = $str_arr[0];
$pageTitle = strrev($pageTitle);
echo $pageTitle;

This should work.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement