Jump to content

Need help in string manipulation


kks_krishna

Recommended Posts

 

HI,

 

I have the following url :

 

http://www.sitename.com/articles/2007/10/article-title-name/2

 

I want to get only the "article-title-name" from the entire url. How can I do that? some time the url will be  "http://www.sitename.com/articles/2007/10/article-title-name/". it is first page of the article. Please help me.

Link to comment
https://forums.phpfreaks.com/topic/73922-need-help-in-string-manipulation/
Share on other sites

If you was going to use RegEx, this would be simpler!

 

<?php
//Get the URI (from the address bar)
#$str = $_SERVER['REQUEST_URI'];
$str = 'http://www.sitename.com/articles/2007/10/article-title-name/2';
preg_match_all('%/([^/]*)%i', $str, $result, PREG_PATTERN_ORDER);
$bits = $result[1];

echo $bits[5];

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.