Jump to content

[SOLVED] Just cut it short!


TheFilmGod

Recommended Posts

try using .htaccess to modify your pages.

 

no thank you. .htaccess shouldn't be used for a simple php script for a various of reasons. I know you can use $_SERVER['something'] and then somehow cut out that link into just what I want.

 

Anyone else!?

Link to comment
Share on other sites

what does $_SERVER['REQUEST_URI']; do?

 

According to the php manual it ges the url of the requested page, i.e. index.php . But I don't want the "requested page" I want the whole url and cut it short! I'm looking for the name of the first directory.

 

So, website.com/news/index/hi/hello.php

 

= news

 

So I want the text after .com/ and all the way to the next "/". Sounds simple but its giving me a headache! Help!!!

 

And wouldn't the use of substr(); be enough without the strpos();?

Link to comment
Share on other sites

How can I retrive the full url of the current page and cut everything off but the end of it, like so:

 

http://blah.website.com/news/index.php

 

INTO --> news

 

or

 

http://www.website.com/index.php

 

INTO --> index

 

Please help! I'm a noob.

 

that the post i answered whats wrong genius?

 

or try

http://www.php.net/manual/en/function.realpath.php

Link to comment
Share on other sites

:D That's just one of the problems with it.

Read the docs dude.

Also, I will repeat: Those functions are for working with FILES. Not the current url of the page a visitor is viewing. Not going to work here.

 

The OP is obviously off working on the code, and if he needs help he'll post. The requirements he posted were a bit confusing but with some more url examples we can probably get it working.

Link to comment
Share on other sites

use echo LOL you cant see anything because you dont print it lol

$path = 'http://blah.website.com/news/index.php';

echo basename($path, ".php"); //gives index

 

echo realpath($path);//should give news

 

 

 

Use a combination of the following:

$_SERVER['REQUEST_URI'];

substr();

strpos();

See if you can get anything with that, and if not we can help more.

 

@josirose is that the code your talking? i guess long and not dyanmic

Link to comment
Share on other sites

use echo LOL you cant see anything because you dont print it lol

$path = 'http://blah.website.com/news/index.php';

echo basename($path, ".php"); //gives index

 

echo realpath($path);//should give news

 

 

 

Use a combination of the following:

$_SERVER['REQUEST_URI'];

substr();

strpos();

See if you can get anything with that, and if not we can help more.

 

@josirose is that the code your talking? i guess long and not dyanmic

 

 

GODDAMNIT STILL NOTHING...

Link to comment
Share on other sites

I love how I left for like 20 minutes and a whole argument sparked out!! Please mods don't lock this thread, I didn't do nothing!!

 

LOL!  ;D

 

jesirose, you were right all the time abut the argument...

 

Anwaz, I tried $_SERVER['REQUEST_URI'];and echo the results.

 

I got the full path except the annoying http://www.website.com thing. This is a good start.

 

Now how do I use the string functions? I mean I know how to do it if the name was only like index.php but it may be news/extra/hello/blah.php? how do I do that?

 

Sorry, I'm a newbie, a.k.a a NOOB!  :P

 

Link to comment
Share on other sites

So you know one part of it you want to remove - anything before and including website.com.

So find the position of website.com - using strpos.

Then make a substring which goes from the end of website.com to the end of the string. Remember strpos gives you the start of the string so you'll need to add the strlen of website.com to the strpos to get the END of website.com

 

Then we'll go from there.

Can you give more examples of what you're trying to get?

like, 5 example URLs and which part you want. I know you said always the last, but one example you gave was index.php?

Link to comment
Share on other sites

I made my own!!

 

<?php
$full = $_SERVER['REQUEST_URI'];

$url = ltrim("$full", "/");

$path = substr($url, 0, strpos("$url", "/"));
echo "$path";
?>

 

Now, $_SERVER['REQUEST_URI'] always gets whatever is after:

 

website.com...

 

so I don't have to worry about that, I simply then take the string and trim off the "/" from the left side. I find the offset that tells me when the next "/" is there and then I take the string from the beginning to the offset.

 

many thanks to jesirose. She is a genius. Thanks to teng84, too. I"m sure your code works too, but I like to use mine. NOt in the mood to steal today!  :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.