Hi there,
i have a site with fake folders & files.
htaccess rewrites everything to index.php?vars
now in index.php i decide what file to include with a switch/case
statement.
to define where i am, i explode the query string, and check $array[0]
where i am for the main section.
Only now if there are two slashes behind each other
(folder//subfolder), the value inbetween ( '' )
gets ignored, though in 'real' it would give an error. How can i have
explode telling
me that value is '' ?
I hope you understand (sorry for my english)
Frizzle. 12 2887
frizzle wrote: Only now if there are two slashes behind each other (folder//subfolder)
Best thing is to make sure explode() never even sees that.
<?php
$url = 'folder//subfolder/////somefile';
while (strstr($url, '//'))
$url = str_replace('//', '/', $url);
$parts = explode('/', $url);
print $parts[0]; /* prints 'folder' */
print $parts[1]; /* prints 'subfolder' */
print $parts[2]; /* prints 'somefile' */
?>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Toby Inkster wrote: frizzle wrote:
Only now if there are two slashes behind each other (folder//subfolder)
Best thing is to make sure explode() never even sees that.
<?php $url = 'folder//subfolder/////somefile';
while (strstr($url, '//')) $url = str_replace('//', '/', $url);
$parts = explode('/', $url);
print $parts[0]; /* prints 'folder' */ print $parts[1]; /* prints 'subfolder' */ print $parts[2]; /* prints 'somefile' */ ?>
-- Toby A Inkster BSc (Hons) ARCS Contact Me ~ http://tobyinkster.co.uk/contact
Well, i figured right now, explode ignores it, and goes past it.
The way you present it, is axactly what it does right now w/o any
str_repl().
What i'd like is to have $array[1] to be empry or null, etc.
I hope you get it.
Frizzle.
frizzle wrote: Toby Inkster wrote: frizzle wrote:
Only now if there are two slashes behind each other (folder//subfolder) Best thing is to make sure explode() never even sees that.
<?php $url = 'folder//subfolder/////somefile';
while (strstr($url, '//')) $url = str_replace('//', '/', $url);
$parts = explode('/', $url);
[snip] Well, i figured right now, explode ignores it, and goes past it. The way you present it, is axactly what it does right now w/o any str_repl().
Can you post an example of code that will do that. You must be doing
something else that removes the empty values.
What i'd like is to have $array[1] to be empry or null, etc.
That is what explode should give you, if you got nothing in between
two separators. If you take Toby's code without the while/str_replace,
then you should get:
Array
(
[0] => folder
[1] =>
[2] => subfolder
[3] =>
[4] =>
[5] =>
[6] =>
[7] => somefile
)
/Bent
Bent Stigsen wrote: frizzle wrote: Toby Inkster wrote: frizzle wrote:
Only now if there are two slashes behind each other (folder//subfolder) Best thing is to make sure explode() never even sees that.
<?php $url = 'folder//subfolder/////somefile';
while (strstr($url, '//')) $url = str_replace('//', '/', $url);
$parts = explode('/', $url); [snip] Well, i figured right now, explode ignores it, and goes past it. The way you present it, is axactly what it does right now w/o any str_repl().
Can you post an example of code that will do that. You must be doing something else that removes the empty values.
What i'd like is to have $array[1] to be empry or null, etc.
That is what explode should give you, if you got nothing in between two separators. If you take Toby's code without the while/str_replace, then you should get: Array ( [0] => folder [1] => [2] => subfolder [3] => [4] => [5] => [6] => [7] => somefile )
/Bent
function DefineLoc(){
$loc = explode('/', $_SERVER['QUERY_STRING'], ) );
return $loc;
};
The function worked that way for me. Also, when i had trailing slashes,
the current location would differ from w/o any trailing slashes.
Now i have this:
function DefineLoc(){
$loc = explode('/', trim( $_SERVER['QUERY_STRING'], '/' ) );
return $loc;
};
But that's also not as it should be but fixes the trailing problem.
Frizzle.
frizzle wrote:
[snip] Now i have this: function DefineLoc(){ $loc = explode('/', trim( $_SERVER['QUERY_STRING'], '/' ) ); return $loc; };
But that's also not as it should be but fixes the trailing problem.
I don't think I quite understand what you want.
Can you give an example value of $_SERVER['QUERY_STRING'], and how the
array returned from DefineLoc should look like.
/Bent
Bent Stigsen wrote: frizzle wrote: [snip] Now i have this: function DefineLoc(){ $loc = explode('/', trim( $_SERVER['QUERY_STRING'], '/' ) ); return $loc; };
But that's also not as it should be but fixes the trailing problem.
I don't think I quite understand what you want.
Can you give an example value of $_SERVER['QUERY_STRING'], and how the array returned from DefineLoc should look like.
/Bent
$_SERVER['QUERY_STRING'] =
'/artists/nirvana/mtv_unplugged/about_a_girl.html'
$array[0] => artists
$array[1] => nirvana
$array[2] => mtv_unplugged
$array[3] => about_a_girl.html
$_SERVER['QUERY_STRING'] = '/artists/nirvana/mtv_unplugged/'
$array[0] => artists
$array[1] => nirvana
$array[2] => mtv_unplugged
$array[3] => NULL
$_SERVER['QUERY_STRING'] = '/artists/nirvana/mtv_unplugged'
$array[0] => artists
$array[1] => nirvana
$array[2] => mtv_unplugged
$array[3] => NULL
$_SERVER['QUERY_STRING'] = '/artists//mtv_unplugged/'
$array[0] => artists
$array[1] => NULL
$array[2] => mtv_unplugged
$array[3] => NULL
I hope you understand what i mean/want.
Frizzle.
frizzle wrote:
[snip] $_SERVER['QUERY_STRING'] = '/artists/nirvana/mtv_unplugged' $array[0] => artists $array[1] => nirvana $array[2] => mtv_unplugged $array[3] => NULL
[snip]
This one above is your real problem. You would need some mechanism to
determine what kind last element is, file or part of path. A lazy way
could be to set the criteria or just make the assumption that files
always has an attached extension (i.e. '.' in the name).
For instance:
function DefineLoc(){
$loc = explode('/', trim( $_SERVER['QUERY_STRING'], '/' ) );
if (strrpos(end($loc), '.')===false) $loc[] = null;
reset($loc);
return $loc;
};
If you have pathnames containing '.', then you would have to write
some code that can make the distinction.
/Bent
Bent Stigsen wrote: frizzle wrote: [snip] $_SERVER['QUERY_STRING'] = '/artists/nirvana/mtv_unplugged' $array[0] => artists $array[1] => nirvana $array[2] => mtv_unplugged $array[3] => NULL [snip]
This one above is your real problem. You would need some mechanism to determine what kind last element is, file or part of path. A lazy way could be to set the criteria or just make the assumption that files always has an attached extension (i.e. '.' in the name).
For instance: function DefineLoc(){ $loc = explode('/', trim( $_SERVER['QUERY_STRING'], '/' ) ); if (strrpos(end($loc), '.')===false) $loc[] = null; reset($loc); return $loc; };
If you have pathnames containing '.', then you would have to write some code that can make the distinction.
/Bent
Actually what i have is quite similar to what you suggest. But it still
doesn't solve my double slash problem, where the value should be NULL.
The thingy i have to check if a filename is specified is the following:
if( preg_match( '/(\.html)$/', $loc[3] ) ){
$song_url = preg_replace( '/(\.html)$/', '', $loc[3] );
$song_extension = TRUE;
}else{
$song_extension = FALSE;
};
It checks all values in the array are UrlSafe(), wich means that they
are A-z, 0-9, -, _ That's also why i delete the last '.html', because
else validation would return false.
Frizzle.
frizzle wrote: $_SERVER['QUERY_STRING'] = '/artists//mtv_unplugged/'
$array = explode('/', $_SERVER['QUERY_STRING']);
array_shift($array);
for ($i=0;$i<4;$i++)
if (!strlen($array[$i]))
$array[$i] = 'NULL';
$array[0] => artists $array[1] => NULL $array[2] => mtv_unplugged $array[3] => NULL
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
frizzle wrote: Bent Stigsen wrote: frizzle wrote: [snip] $_SERVER['QUERY_STRING'] = '/artists/nirvana/mtv_unplugged' $array[0] => artists $array[1] => nirvana $array[2] => mtv_unplugged $array[3] => NULL [snip]
This one above is your real problem. You would need some mechanism to determine what kind last element is, file or part of path. A lazy way could be to set the criteria or just make the assumption that files always has an attached extension (i.e. '.' in the name).
For instance: function DefineLoc(){ $loc = explode('/', trim( $_SERVER['QUERY_STRING'], '/' ) ); if (strrpos(end($loc), '.')===false) $loc[] = null; reset($loc); return $loc; };
If you have pathnames containing '.', then you would have to write some code that can make the distinction.
/Bent
Actually what i have is quite similar to what you suggest. But it still doesn't solve my double slash problem, where the value should be NULL.
If I run this:
$url = '/artists//mtv_unplugged/';
$loc = explode('/', trim( $url, '/' ) );
if (strrpos(end($loc), '.')===false) $loc[] = null;
print_r($loc);
I get:
Array
(
[0] => artists
[1] =>
[2] => mtv_unplugged
[3] =>
)
Isn't that what you want?
/Bent
[snip]
Let me guess it, you did mod_rewite
RewriteRule ^/(.+?)$ index.php?$1
Is that what you want?
<?php
$requested_page = $_SERVER['QUERY_STRING'];
$requested_page = preg_replace('~/+~', '/', $requested_page);
$requested_tree = explode('/', $requested_page);
?>
I tested with http://localhost/test5.php?folder///...der///yo///lol and it said
that
$requested_tree is Array (
[0] => folder
[1] => subfolder
[2] => yo
[3] => lol
)
the DtTvB wrote: Let me guess it, you did mod_rewite RewriteRule ^/(.+?)$ index.php?$1
Is that what you want? <?php $requested_page = $_SERVER['QUERY_STRING']; $requested_page = preg_replace('~/+~', '/', $requested_page); $requested_tree = explode('/', $requested_page); ?>
I tested with http://localhost/test5.php?folder///...der///yo///lol and it said that $requested_tree is Array ( [0] => folder [1] => subfolder [2] => yo [3] => lol )
I have mod-rewrite:
RewriteBase /testfolder/
RewriteRule ^(index\.php)$ - [L]
RewriteRule ^(img|swf|js|css)/.*$ - [L]
RewriteRule ^(.*)$ index.php?$1 [L]
But this also still gives me problems as stated on http://groups.google.com/group/alt.a...d6bc52b4feece4
Frizzle. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark |
last post by:
Hello,
I have been searching for a reason for this behavior but no solution
so I figured I would ask.
Basically I have a web page that displays data in a database to the
user for...
|
by: William Krick |
last post by:
I have a string containing concatenated ascii "records" that are each
terminated by '\n'.
For testing purposes, I construct sample data like this...
$mystring =...
|
by: Richard Lawrence |
last post by:
Hi there,
I'm having a problem with PHP which I'm not sure how to best solve.
Here is the code:
$fp = fopen("comments.txt", "r");
while(!feof($fp))
{
$line = fgets($fp, 1024);
list($key,...
|
by: |
last post by:
I am working on a web/webservice application that has a service layer. Most
service methods will perform an access-check before executing. This check
uses the IPrincipal credentials available in...
|
by: FFMG |
last post by:
Hi,
I need the php equivalent of explode in one of my app.
I read a very big file and "explode" each line to fill a structure.
The reading of the file, 19Mb, (I will also need to streamline...
|
by: Joe |
last post by:
I have a 'random quotes' plugin that I use which reads tab delimited
quotes from multiple text files in a directory, and then randomly
displays one. Each text file contains multiple lines, each...
|
by: k04jg02 |
last post by:
Python has a nifty operator that will take a container and pass its
elements as function parameters. In Python you can make a list like
so:
x =
Then you can say:
f(*x)
|
by: tolkienarda |
last post by:
hi everyone
i am getting a bunch of values from a form via post all of the information that this question deals with is from series of check boxes below is the code that creates the check boxes...
|
by: sathyashrayan |
last post by:
Dear group,
The function to be used as follows:
$links = "http://www.campaignindia.in/feature/analysis";
$tag1 = '<div class=feature-wrapper>';
$tag2 = '<h1><a href';
$tag3 = "</a>";
$op =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |