Author Topic: [SOLVED] Just cut it short!  (Read 932 times)

0 Members and 1 Guest are viewing this topic.

Offline jesirose

  • Fanatic
  • Posts: 3,819
  • Gender: Female
  • PHP Goddess
    • View Profile
    • Reed's Training Blog
Re: Just cut it short!
« Reply #15 on: August 30, 2007, 08:36:29 PM »
: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.
Every time you post "It didn't work" without more explanation, God kills a kitten.
When you post code without code tags, He just teases a puppy. But it's still sad.
What does that php function do? | What does that term mean? | I don't see any errors! | Awesome API Interface
PHP Goddess with Attitude since 2004

Offline teng84

  • Fanatic
  • Posts: 3,546
  • Gender: Male
    • View Profile
Re: Just cut it short!
« Reply #16 on: August 30, 2007, 08:37:29 PM »
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

Offline phpSensei

  • i can haz cool title?
  • Addict
  • Posts: 2,808
  • Everybody wants Kung-Fu Fighting
    • View Profile
    • Website Development Company
Re: Just cut it short!
« Reply #17 on: August 30, 2007, 08:40:35 PM »
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...
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."  — C.A.R. Hoare, The 1980 ACM Turing Award Lecture

Offline jesirose

  • Fanatic
  • Posts: 3,819
  • Gender: Female
  • PHP Goddess
    • View Profile
    • Reed's Training Blog
Re: Just cut it short!
« Reply #18 on: August 30, 2007, 08:41:01 PM »
Did you try your code? You say it "should give news" - DOES it?
No. It doesn't:
http://grady.us/temp/test.php

If you want to fix it go ahead. My code works fine, and is perfectly dynamic. I use it as the base for my framework I use on every site I do.
Every time you post "It didn't work" without more explanation, God kills a kitten.
When you post code without code tags, He just teases a puppy. But it's still sad.
What does that php function do? | What does that term mean? | I don't see any errors! | Awesome API Interface
PHP Goddess with Attitude since 2004

Offline teng84

  • Fanatic
  • Posts: 3,546
  • Gender: Male
    • View Profile
Re: Just cut it short!
« Reply #19 on: August 30, 2007, 08:56:32 PM »
oops my bad even if my codes run still it wont work I should have read the post clearly
SORRY people I thought its only the path not the URL :P :P :P :P

ignore my post LOL

Offline phpSensei

  • i can haz cool title?
  • Addict
  • Posts: 2,808
  • Everybody wants Kung-Fu Fighting
    • View Profile
    • Website Development Company
Re: Just cut it short!
« Reply #20 on: August 30, 2007, 09:00:12 PM »
oops my bad even if my codes run still it wont work I should have read the post clearly
SORRY people I thought its only the path not the URL :P :P :P :P

ignore my post LOL

its okay....its k...
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."  — C.A.R. Hoare, The 1980 ACM Turing Award Lecture

Offline TheFilmGodTopic starter

  • Addict
  • Posts: 1,933
  • Gender: Male
    • View Profile
Re: Just cut it short!
« Reply #21 on: August 30, 2007, 09:14:11 PM »
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
 
The future is here.

Offline jesirose

  • Fanatic
  • Posts: 3,819
  • Gender: Female
  • PHP Goddess
    • View Profile
    • Reed's Training Blog
Re: Just cut it short!
« Reply #22 on: August 30, 2007, 09:16:53 PM »
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?
Every time you post "It didn't work" without more explanation, God kills a kitten.
When you post code without code tags, He just teases a puppy. But it's still sad.
What does that php function do? | What does that term mean? | I don't see any errors! | Awesome API Interface
PHP Goddess with Attitude since 2004

Offline teng84

  • Fanatic
  • Posts: 3,546
  • Gender: Male
    • View Profile
Re: Just cut it short!
« Reply #23 on: August 30, 2007, 09:28:18 PM »
Code: [Select]

$x=explode('?',$_SERVER['REQUEST_URI']);
echo basename($x[0],'.php').'<br/>';
$x= explode ('/',$_SERVER['REQUEST_URI']);
echo $x[count($x)-2];
[code]

OK people this is tested and that works  :P :P :P :P
[/code]

Offline TheFilmGodTopic starter

  • Addict
  • Posts: 1,933
  • Gender: Male
    • View Profile
Re: Just cut it short!
« Reply #24 on: August 30, 2007, 09:51:42 PM »
I made my own!!

Code: [Select]
<?php
$full 
$_SERVER['REQUEST_URI'];

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

$path substr($url0strpos("$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
The future is here.

Offline jesirose

  • Fanatic
  • Posts: 3,819
  • Gender: Female
  • PHP Goddess
    • View Profile
    • Reed's Training Blog
Re: [SOLVED] Just cut it short!
« Reply #25 on: August 30, 2007, 09:53:46 PM »
W00t I am a genius.
Every time you post "It didn't work" without more explanation, God kills a kitten.
When you post code without code tags, He just teases a puppy. But it's still sad.
What does that php function do? | What does that term mean? | I don't see any errors! | Awesome API Interface
PHP Goddess with Attitude since 2004

Offline teng84

  • Fanatic
  • Posts: 3,546
  • Gender: Male
    • View Profile
Re: [SOLVED] Just cut it short!
« Reply #26 on: August 30, 2007, 09:55:08 PM »
hep hep horay  ;D ;D
i vote jesirose

Offline phpSensei

  • i can haz cool title?
  • Addict
  • Posts: 2,808
  • Everybody wants Kung-Fu Fighting
    • View Profile
    • Website Development Company
Re: [SOLVED] Just cut it short!
« Reply #27 on: August 30, 2007, 09:56:10 PM »
php brings cheers to people....

"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."  — C.A.R. Hoare, The 1980 ACM Turing Award Lecture