Solved

want a portion of the url

Posted on 2013-01-11
4
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Cornelia Yoder
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:
Cornelia Yoder 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

751 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