Solved

want a portion of the url

Posted on 2013-01-11
4
194 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

832 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