Solved

want a portion of the url

Posted on 2013-01-11
4
195 Views
Last Modified: 2013-01-11
website.com/file.php

want 'file'

and not .php


http://www.site.net/fileName.php

want fileName
0
Comment
Question by:rgb192
  • 2
4 Comments
 
LVL 27

Expert Comment

by:yodercm
ID: 38769305
First use explode() to separate the portions between slashes.
Then use explode() again on the last section to separate the last section at the dot.

Will this format for the url be always so simple?  Or might it be more complex, such as

http://www.xxx.yyy.zzz.com/abc.def.php ?

If so, precisely define the portion you want, and we can find it.

http://us1.php.net/manual/en/function.explode.php
0
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 38769313
If you have only the simple url format as shown, this will work:


<?php

$url ='http://www.site.net/fileName.php';

$array1 = explode("/", $url);
$cnt = count($array1);
$array2 = explode(".", $array1[$cnt-1]);
$filename = $array2[0];


echo $filename;

exit;
0
 

Expert Comment

by:lucasnc
ID: 38769412
The simplest medium would be to add the following code to your .htaccess file.  Once done, you should be able to go to http://example.com/index instead of http://example.com/index.html.

Options +MultiViews

Open in new window

Keep in mind that this will work only in an instance where you don't have two instances of the same file name.  For example, if you have both "index.html" and "index.php", the server will have to make its best guess as to which file you want it to serve up.  If you have a /secure/ directory and a file entitled "secure.html", directories take priority over files, so browsing to http://example.com/secure will bring you to the content of that directory and not http://example.com/secure.html.

Hope this helps.
0
 

Author Closing Comment

by:rgb192
ID: 38769477
only using php and not htacess

this solved the problem

thanks
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question