Solved

want a portion of the url

Posted on 2013-01-11
4
187 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
only using php and not htacess

this solved the problem

thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now