Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove characters? 1

Status
Not open for further replies.

idtstudios2

Programmer
Aug 12, 2005
35
0
0
US
I have a bunch of links that are formated like so:


Now obviously "monkey" is just an example tag. In reality the tags would nearly always be different. What I need is to be able to pass the link to a function as a string and have the function return only the tag. ex:

pass:
and get: war

Now, I know how to take individual characters out of a string, but I am at a complete loss on how to remove everything but the tag from such a link?

And ideas or functions out there?
Thanks
 
this code should do what you want

Code:
<?
$url = "[URL unfurl="true"]http://blah.com/tags/war/";[/URL]

echo get_tag($url);

function get_tag($url)
{
	$p_url = parse_url($url);
	if (!empty($p_url['path'])):
		$path = explode ("/", trim ($p_url['path'], "/")); //gets rid of starting and trailing slash then splits the path string into an array separated by the slash
		return ($path[count($path)-1]); // returns the last element of the array
	else:
		die("no path specified in the url");
	endif;
}
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top