Log in

View Full Version : [PHP TUT] Explode and showing paths.



Hypertext
10-02-2008, 07:55 PM
Today I'm going to show you about how to explode a path, eg example.com/dir/extra/link/etc.php becomes Dir Extra Link Etc. Essentially making it easy to build on to become Dir --> Extra --> Link --> Etc. Etc :)
Heres the code:

<?php
$path = $_SERVER['PHP_SELF']; // returns /home/attack/kill/etc.php

$valuesArray = explode("/",$path); // exploding the path

/* returns:
$valuesArray[0] = ""
$valuesArray[1] = "home"
$valuesArray[2] = "attack"
$valuesArray[3] = "kill"
$valuesArray[4] = "etc.php" // arrays
*/

foreach ($valuesArray as $value){

$name = explode(".",$value); // exploding again
echo $name[0]; // echoing the path part w/o

if($name[1] == ""){
echo " &nbsp; &gt; &nbsp;"; // checking the path.
}
}

?>
Enjoy!

QuickScriptz
11-02-2008, 12:38 AM
Nice tutorial, although some real-life uses for it may have also helped - but overall good work. +Rep :)

Zedtu
11-02-2008, 01:49 AM
Either I am too tired to spot it, or something (been working for the past 20 hours)

You forgot to upper case the directory ;)

Hypertext
11-02-2008, 05:04 AM
Real life uses!?!???!

Hmm:
http://habboxforum.com/images/misc/navbits_start.gif (http://habboxforum.com/showthread.php?t=453919#) Habbox UK Forum (http://habboxforum.com/index.php) > Technology + The Web (http://habboxforum.com/forumdisplay.php?f=125) > Designing & Development (http://habboxforum.com/forumdisplay.php?f=56) http://habboxforum.com/images/misc/navbits_finallink_ltr.gif (http://habboxforum.com/showthread.php?t=453919) [PHP TUT] Explode and showing paths.
enough said? obviously harder to do using url vars but ya know.

Invent
11-02-2008, 03:59 PM
Real life uses!?!???!

Hmm:
Habbox UK Forum > Technology + The Web > Designing & Development [PHP TUT] Explode and showing paths.
enough said? obviously harder to do using url vars but ya know.

Dude, that doesn't use explode to parse variables...

The information is grabbed from an SQL Database which has no relevance to what you posted..

Blob
11-02-2008, 04:42 PM
Ye, like a MyBB board adds to the breadcrumb what ever it is. You dont see the link of this forum as

http://www.habboxforum.com/Habbox UK Forum/Technology + The Web/Designing & Development/[PHP TUT] Explode and showing paths/

Do you?

--ss--
11-02-2008, 04:44 PM
What exactly does it do?

Agnostic Bear
11-02-2008, 05:02 PM
What exactly does it do?

I don't know but something completely ******ed by the looks of it.

That would end up not showing file extensions which are pretty useful to have :rolleyes:

Blob
11-02-2008, 05:03 PM
And if you have a directory, e.g suspended.page/ then it wouldn't show .page

Hypertext
11-02-2008, 05:20 PM
Yeh its basically showing a nicer looking path. Umm. Yeh I was wrong about the Path :P but some people do use it, and it can be used sometimes.

RYANNNNN
11-02-2008, 07:39 PM
I use explode in a function that gets the search term from referring search engines.

Zedtu
11-02-2008, 08:41 PM
I use explode in a function that gets the search term from referring search engines.
Congratulations?

I am pretty sure this thread is not about showing search terms, it is a tutorial about exploding a URL and making a "primitive" breadcrumb with it.

Nothing about search engines and what you do with them?

QuickScriptz
11-02-2008, 09:22 PM
Real life uses!?!???!

Hmm:
http://habboxforum.com/images/misc/navbits_start.gif (http://habboxforum.com/showthread.php?t=453919#) Habbox UK Forum (http://habboxforum.com/index.php) > Technology + The Web (http://habboxforum.com/forumdisplay.php?f=125) > Designing & Development (http://habboxforum.com/forumdisplay.php?f=56) http://habboxforum.com/images/misc/navbits_finallink_ltr.gif (http://habboxforum.com/showthread.php?t=453919) [PHP TUT] Explode and showing paths.
enough said? obviously harder to do using url vars but ya know.

Although Simon already said this I will repeat it maybe with a little more clarity. A forum uses a system of 'make-believe' folders and sub-folders. What you pasted there does not use the explode() function.


Congratulations?

I am pretty sure this thread is not about showing search terms, it is a tutorial about exploding a URL and making a "primitive" breadcrumb with it.

Nothing about search engines and what you do with them?

Well... it's a thread about 'Explode and showing paths' which would be quite relevant if the referring search engines send a query in the form of a url (eg. 'http://yoursite.com/search/your+term+here'). Try and be a little more positive people :)

Zedtu
11-02-2008, 09:26 PM
Although Simon already said this I will repeat it maybe with a little more clarity. A forum uses a system of 'make-believe' folders and sub-folders. What you pasted there does not use the explode() function.



That is just a breadcrumb of the specific forums it is in.

Forum Title -> Parent -> Sub-Forum -> Thread





Well... it's a thread about 'Explode and showing paths' which would be quite relevant if the referring search engines send a query in the form of a url (eg. 'http://yoursite.com/search/your+term+here' (http://yoursite.com/search/your+term+here%27)). Try and be a little more positive people :)

But it isn't a thread about explode in general?

The whole reason of a "breadcrumb" is to allow easier navigation, just like parent folders in a file system.


Example:
/images/bob

Parent Folder - /images/
File1 - PNG
File2 - GIF
Folder2 - /images/bob/hello


So if a search engine is sending queries to your site, its really not going to matter, as that search engine is the only thing that sees it.

If a search engine is sending you to a search page on your site.. and it is a search engine like vBulletins, its not going to matter, as those are based on search ids, and it will just give you an error.

Hypertext
11-02-2008, 09:37 PM
I already said I was wrong about the breadcrumbs for forums, but it re enacts that :P

QuickScriptz
11-02-2008, 09:42 PM
But it isn't a thread about explode in general?

The whole reason of a "breadcrumb" is to allow easier navigation, just like parent folders in a file system.


Example:
/images/bob

Parent Folder - /images/
File1 - PNG
File2 - GIF
Folder2 - /images/bob/hello


So if a search engine is sending queries to your site, its really not going to matter, as that search engine is the only thing that sees it.

If a search engine is sending you to a search page on your site.. and it is a search engine like vBulletins, its not going to matter, as those are based on search ids, and it will just give you an error.

I think you misunderstood me... I was the one pointing out to you that it was a thread about explode in general ;) His comment would just be helpful to give another example of where explode can be used.

RYANNNNN
12-02-2008, 10:52 AM
Congratulations?

I am pretty sure this thread is not about showing search terms, it is a tutorial about exploding a URL and making a "primitive" breadcrumb with it.

Nothing about search engines and what you do with them?

Thank you.

Infact, my response was to Scriptz as he asked about proper uses. Please read through the read first instead of trying to make me look like a fool, because the only fool around here is you.

Zedtu
12-02-2008, 12:04 PM
Thank you.

Infact, my response was to Scriptz as he asked about proper uses. Please read through the read first instead of trying to make me look like a fool, because the only fool around here is you.
What have I ever done to you?

Back when I was Dentafrice you never said nothing to me.

If you would like to "e-argue" feel free to PM me.

If you were directing that at someone, there is a quote feature.

MrCraig
12-02-2008, 01:18 PM
is



<?php
echo($_SERVER['PHP_SELF']);
?>


the same as


<?php
echo($_SERVER['REQUEST_URI']);
?>


?

Want to hide these adverts? Register an account for free!