php-general Digest 13 Jun 2010 22:52:55 -0000 Issue 6797

Topics (messages 306084 through 306110):

Re: howto run sql script with php?
        306084 by: Ashley Sheridan
        306089 by: Stephan Ebelt
        306092 by: Stephan Ebelt
        306094 by: Brandon Rampersad

PHP - Header ERROR
        306085 by: Don Wieland
        306086 by: Ashley Sheridan
        306087 by: Ashley Sheridan
        306091 by: Don Wieland
        306093 by: Ashley Sheridan
        306096 by: Shawn McKenzie
        306097 by: Steve

Cookie access with CLI
        306088 by: David Èesal
        306090 by: Ashley Sheridan
        306095 by: Shawn McKenzie

String Parse Help for novice
        306098 by: Rick Dwyer
        306099 by: Ashley Sheridan
        306100 by: Karl DeSaulniers
        306101 by: Karl DeSaulniers
        306102 by: Ashley Sheridan
        306103 by: Karl DeSaulniers
        306104 by: Rick Dwyer
        306105 by: Karl DeSaulniers
        306106 by: Ashley Sheridan
        306107 by: Karl DeSaulniers
        306108 by: Ashley Sheridan
        306109 by: Karl DeSaulniers
        306110 by: Rick Dwyer

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Sun, 2010-06-13 at 12:52 +0200, Stephan Ebelt wrote:

> On Sun, Jun 13, 2010 at 11:29:14AM +0200, Peter Lind wrote:
> > On 13 June 2010 11:05, Stephan Ebelt <s...@shared-files.de> wrote:
> > > Hello,
> > >
> > > I am trying to run a .sql script produced with mysql-dump from a php 
> > > script but
> > > failed to find a rudimentary robust solution yet.
> > >
> > > mysql_query() can only run one query at a time. Thus its necessary to 
> > > somehow
> > > parse the input file and separate the queries... which is difficult since 
> > > the
> > > syntax can be quite complex.
> > >
> > 
> > Use mysqli - it supports running multiple queries at once.
> 
> sometimes its as easy as that. I'll give it a try.
> 
> thanks,
> stephan
> 
> 


Why do you have to use PHP at all to do this? You could run the query
directly at the MySQL console.

Failing that, why not use a tool such as phpMyAdmin, which will do all
the hard work for you?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Sun, Jun 13, 2010 at 12:14:53PM +0100, Ashley Sheridan wrote:
>    On Sun, 2010-06-13 at 12:52 +0200, Stephan Ebelt wrote:
> 
>  On Sun, Jun 13, 2010 at 11:29:14AM +0200, Peter Lind wrote:
>  > On 13 June 2010 11:05, Stephan Ebelt <[1]...@shared-files.de> wrote:
>  > > Hello,
>  > >
>  > > I am trying to run a .sql script produced with mysql-dump from a php 
> script but
>  > > failed to find a rudimentary robust solution yet.
>  > >
>  > > mysql_query() can only run one query at a time. Thus its necessary to 
> somehow
>  > > parse the input file and separate the queries... which is difficult 
> since the
>  > > syntax can be quite complex.
>  > >
>  >
>  > Use mysqli - it supports running multiple queries at once.
> 
>  sometimes its as easy as that. I'll give it a try.
> 
>  thanks,
>  stephan
> 
> 
> 
>    Why do you have to use PHP at all to do this? You could run the query
>    directly at the MySQL console.
> 
>    Failing that, why not use a tool such as phpMyAdmin, which will do all the
>    hard work for you?

I use it to deploy schema updates and run unittests. So there are many sql
files running many times actually. Its been working fine for years until I came
up with wanting a trigger recently...

good point to check how phpMyAdmin does this. They must have faced the same
problem.

stephan

> 
>    Thanks,
>    Ash
>    [2]http://www.ashleysheridan.co.uk
> 
> References
> 
>    Visible links
>    1. mailto:s...@shared-files.de
>    2. http://www.ashleysheridan.co.uk/

--- End Message ---
--- Begin Message ---
On Sun, Jun 13, 2010 at 12:52:18PM +0200, Stephan Ebelt wrote:
[...]
> > Use mysqli - it supports running multiple queries at once.
> 
> sometimes its as easy as that. I'll give it a try.

not quite as easy:  mysqli->multi_query() works nice with many queries in a
string but that DELIMITER syntax still produces an error...  

stephan


--- End Message ---
--- Begin Message ---
niggers

On Sun, Jun 13, 2010 at 11:07 AM, Stephan Ebelt <s...@shared-files.de> wrote:

> On Sun, Jun 13, 2010 at 12:52:18PM +0200, Stephan Ebelt wrote:
> [...]
> > > Use mysqli - it supports running multiple queries at once.
> >
> > sometimes its as easy as that. I'll give it a try.
>
> not quite as easy:  mysqli->multi_query() works nice with many queries in a
> string but that DELIMITER syntax still produces an error...
>
> stephan
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
A Brandon_R Production

--- End Message ---
--- Begin Message ---
Hello,

I have a contact form with three fields, name, email, and comment, and a CAPTCHA

I am doing some basic validation for empty fields but am getting a PHP error when trying to redirect back to the original page with an ERROR,

It seems when my COMMENT field contains <BR>s, it generates the PHP ERROR. No <BR?s works perfectly. Am I missing a function for the comment that is necessary for the GET STRING return?

if($_POST['name'] AND $_POST['email'] AND $_POST['comment']) {
}else{
header("location: contactus.php?Error=Missing values in REQUIRED FIELDS&name=".$_POST['name']."&email=".$_POST['email']."&comment=". $_POST['comment']);
exit();
}


session_start();



if($_SESSION['Captcha_Str'] != $_POST['scode']) {
echo "HI";
header("location: contactus.php?Error=You did not enter your SECURITY CODE correctly. It is case sensitive.&name=".$_POST['name']."&email=". $_POST['email']."&comment=".$_POST['comment']);
exit();
}


Don Wieland
D W   D a t a   C o n c e p t s
~~~~~~~~~~~~~~~~~~~~~~~~~
d...@dwdataconcepts.com
Direct Line - (949) 305-2771

Integrated data solutions to fit your business needs.

Need assistance in dialing in your FileMaker solution? Check out our Developer Support Plan at:
http://www.dwdataconcepts.com/DevSup.html

Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9 or higher
http://www.appointment10.com

For a quick overview -
http://www.appointment10.com/Appt10_Promo/Overview.html


--- End Message ---
--- Begin Message ---
On Sun, 2010-06-13 at 06:43 -0700, Don Wieland wrote:

> Hello,
> 
> I have a contact form with three fields, name, email, and comment, and  
> a CAPTCHA
> 
> I am doing some basic validation for empty fields but am getting a PHP  
> error when trying to redirect back to the original page with an ERROR,
> 
> It seems when my COMMENT field contains <BR>s, it generates the PHP  
> ERROR. No <BR?s works perfectly. Am I missing a function for the  
> comment that is necessary for the GET STRING return?
> 
> if($_POST['name'] AND $_POST['email'] AND $_POST['comment']) {
> }else{
> header("location: contactus.php?Error=Missing values in REQUIRED  
> FIELDS&name=".$_POST['name']."&email=".$_POST['email']."&comment=". 
> $_POST['comment']);
> exit();
> }
> 
> 
> session_start();
> 
> 
> 
> if($_SESSION['Captcha_Str'] != $_POST['scode']) {
> echo "HI";
> header("location: contactus.php?Error=You did not enter your SECURITY  
> CODE correctly. It is case sensitive.&name=".$_POST['name']."&email=". 
> $_POST['email']."&comment=".$_POST['comment']);
> exit();
> }
> 
> 
> Don Wieland
> D W   D a t a   C o n c e p t s
> ~~~~~~~~~~~~~~~~~~~~~~~~~
> d...@dwdataconcepts.com
> Direct Line - (949) 305-2771
> 
> Integrated data solutions to fit your business needs.
> 
> Need assistance in dialing in your FileMaker solution? Check out our  
> Developer Support Plan at:
> http://www.dwdataconcepts.com/DevSup.html
> 
> Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro  
> 9 or higher
> http://www.appointment10.com
> 
> For a quick overview -
> http://www.appointment10.com/Appt10_Promo/Overview.html
> 


What exactly is the error you're seeing?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Sun, 2010-06-13 at 07:50 -0700, Don Wieland wrote:

> Yeah - I thought about that, but I don't know how to do this. I have a
> partner who admins my virtual private server. Oh well ;-)
> 
> 
> 
> It is probably something I need to do to the header() string to
> accommodate the <BR>s. I am redirecting back to the original form,
> displaying an ERROR, then re-populating the fields via the GET string.
> The omission of this is CHOKING PHP.
> 
> 
> 
> Don
> 
> 
> On Jun 13, 2010, at 7:39 AM, Ashley Sheridan wrote:
> 
> 
> 
> > Turn on display_errors in your php.ini, or read the error log. That
> > will show you exactly what your error is, and then if you don't know
> > how to fix that error, post it back here.
> 
> 
> 
> Don Wieland
> D W   D a t a   C o n c e p t s
> ~~~~~~~~~~~~~~~~~~~~~~~~~
> d...@dwdataconcepts.com
> Direct Line - (949) 305-2771
> 
> 
> Integrated data solutions to fit your business needs.
> 
> 
> Need assistance in dialing in your FileMaker solution? Check out our
> Developer Support Plan at:
> http://www.dwdataconcepts.com/DevSup.html
> 
> 
> Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro
> 9 or higher
> http://www.appointment10.com
> 
> 
> 
> For a quick overview - 
> 
> http://www.appointment10.com/Appt10_Promo/Overview.html
> 
> 
> 

Add a line in to your .htaccess file then to turn error displaying on.
Note that if this is a live server then you shouldn't really do this,
but if you have to, turn them back off again asap.

php_flag display_errors off

ps. please keep the list copied in, as other people might be able to
benefit from the thread.

psps. please try not to top post; every time you do, a kitten dies ;)

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---

On Jun 13, 2010, at 7:53 AM, Ashley Sheridan wrote:

On Sun, 2010-06-13 at 07:50 -0700, Don Wieland wrote:

Yeah - I thought about that, but I don't know how to do this. I have a
partner who admins my virtual private server. Oh well ;-)



It is probably something I need to do to the header() string to
accommodate the <BR>s. I am redirecting back to the original form,
displaying an ERROR, then re-populating the fields via the GET string.
The omission of this is CHOKING PHP.



Don


On Jun 13, 2010, at 7:39 AM, Ashley Sheridan wrote:



Turn on display_errors in your php.ini, or read the error log. That
will show you exactly what your error is, and then if you don't know
how to fix that error, post it back here.



Don Wieland
D W   D a t a   C o n c e p t s
~~~~~~~~~~~~~~~~~~~~~~~~~
d...@dwdataconcepts.com
Direct Line - (949) 305-2771


Integrated data solutions to fit your business needs.


Need assistance in dialing in your FileMaker solution? Check out our
Developer Support Plan at:
http://www.dwdataconcepts.com/DevSup.html


Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro
9 or higher
http://www.appointment10.com



For a quick overview -

http://www.appointment10.com/Appt10_Promo/Overview.html




Add a line in to your .htaccess file then to turn error displaying on.
Note that if this is a live server then you shouldn't really do this,
but if you have to, turn them back off again asap.

php_flag display_errors off


When I look at my FTP client, I cannot see this .htaccess file. This is a live server, so I am hesitant to find it anyways. I will wait for my partner to assist me with this config so I can see the error.

Unless someone know what I am missing by description. We'll see ;-)


ps. please keep the list copied in, as other people might be able to
benefit from the thread.


OOPS! Sorry, we'll do from now on.

Don

--- End Message ---
--- Begin Message ---
On Sun, 2010-06-13 at 08:06 -0700, Don Wieland wrote:

> On Jun 13, 2010, at 7:53 AM, Ashley Sheridan wrote:
> 
> > On Sun, 2010-06-13 at 07:50 -0700, Don Wieland wrote:
> >
> >> Yeah - I thought about that, but I don't know how to do this. I  
> >> have a
> >> partner who admins my virtual private server. Oh well ;-)
> >>
> >>
> >>
> >> It is probably something I need to do to the header() string to
> >> accommodate the <BR>s. I am redirecting back to the original form,
> >> displaying an ERROR, then re-populating the fields via the GET  
> >> string.
> >> The omission of this is CHOKING PHP.
> >>
> >>
> >>
> >> Don
> >>
> >>
> >> On Jun 13, 2010, at 7:39 AM, Ashley Sheridan wrote:
> >>
> >>
> >>
> >>> Turn on display_errors in your php.ini, or read the error log. That
> >>> will show you exactly what your error is, and then if you don't know
> >>> how to fix that error, post it back here.
> >>
> >>
> >>
> >> Don Wieland
> >> D W   D a t a   C o n c e p t s
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~
> >> d...@dwdataconcepts.com
> >> Direct Line - (949) 305-2771
> >>
> >>
> >> Integrated data solutions to fit your business needs.
> >>
> >>
> >> Need assistance in dialing in your FileMaker solution? Check out our
> >> Developer Support Plan at:
> >> http://www.dwdataconcepts.com/DevSup.html
> >>
> >>
> >> Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro
> >> 9 or higher
> >> http://www.appointment10.com
> >>
> >>
> >>
> >> For a quick overview -
> >>
> >> http://www.appointment10.com/Appt10_Promo/Overview.html
> >>
> >>
> >>
> >
> > Add a line in to your .htaccess file then to turn error displaying on.
> > Note that if this is a live server then you shouldn't really do this,
> > but if you have to, turn them back off again asap.
> >
> > php_flag display_errors off
> >
> 
> When I look at my FTP client, I cannot see this .htaccess file. This  
> is a live server, so I am hesitant to find it anyways. I will wait for  
> my partner to assist me with this config so I can see the error.
> 
> Unless someone know what I am missing by description. We'll see ;-)
> 
> 
> > ps. please keep the list copied in, as other people might be able to
> > benefit from the thread.
> >
> 
> OOPS! Sorry, we'll do from now on.
> 
> Don


If the file doesn't exist you can make it. Some FTP clients may hide the
file as it begins with a period. By default, this character is used to
hide files on *nix-based systems. Windows tends to choke every now and
again on .htaccess files, as it sees it as a file with no name and just
an extension.

You mentioned that there were newline characters in the URL you were
attempting to redirect to. URLs can't contain newline characters, so
that could be causing it to choke. If in doubt, put the URL into a
string first and echo that out and see what the result is. You may need
to view the source of the output in your browser, as the browser will be
treating that string as HTML by default, which treats whitespace
differently.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On 06/13/2010 08:43 AM, Don Wieland wrote:
> Hello,
> 
> I have a contact form with three fields, name, email, and comment, and a
> CAPTCHA
> 
> I am doing some basic validation for empty fields but am getting a PHP
> error when trying to redirect back to the original page with an ERROR,
> 
> It seems when my COMMENT field contains <BR>s, it generates the PHP
> ERROR. No <BR?s works perfectly. Am I missing a function for the comment
> that is necessary for the GET STRING return?
> 
> if($_POST['name'] AND $_POST['email'] AND $_POST['comment']) {
> }else{
> header("location: contactus.php?Error=Missing values in REQUIRED
> FIELDS&name=".$_POST['name']."&email=".$_POST['email']."&comment=".$_POST['comment']);
> 
> exit();
> }
> 
> 
> session_start();
> 
> 
> 
> if($_SESSION['Captcha_Str'] != $_POST['scode']) {
> echo "HI";
> header("location: contactus.php?Error=You did not enter your SECURITY
> CODE correctly. It is case
> sensitive.&name=".$_POST['name']."&email=".$_POST['email']."&comment=".$_POST['comment']);
> 
> exit();
> }
> 
> 
> Don Wieland
> D W   D a t a   C o n c e p t s
> ~~~~~~~~~~~~~~~~~~~~~~~~~
> d...@dwdataconcepts.com
> Direct Line - (949) 305-2771
> 
> Integrated data solutions to fit your business needs.
> 
> Need assistance in dialing in your FileMaker solution? Check out our
> Developer Support Plan at:
> http://www.dwdataconcepts.com/DevSup.html
> 
> Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9
> or higher
> http://www.appointment10.com
> 
> For a quick overview -
> http://www.appointment10.com/Appt10_Promo/Overview.html
> 
> 

You still haven't given us what ERROR you receive, but you need to
urlencode() $_POST['comment'] and the other values in the URL query string.

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
On 6/13/2010 9:37 AM, Shawn McKenzie wrote:
On 06/13/2010 08:43 AM, Don Wieland wrote:
Hello,

I have a contact form with three fields, name, email, and comment, and a
CAPTCHA

I am doing some basic validation for empty fields but am getting a PHP
error when trying to redirect back to the original page with an ERROR,

It seems when my COMMENT field contains<BR>s, it generates the PHP
ERROR. No<BR?s works perfectly. Am I missing a function for the comment
that is necessary for the GET STRING return?

if($_POST['name'] AND $_POST['email'] AND $_POST['comment']) {
}else{
header("location: contactus.php?Error=Missing values in REQUIRED
FIELDS&name=".$_POST['name']."&email=".$_POST['email']."&comment=".$_POST['comment']);

exit();
}


session_start();



if($_SESSION['Captcha_Str'] != $_POST['scode']) {
echo "HI";
header("location: contactus.php?Error=You did not enter your SECURITY
CODE correctly. It is case
sensitive.&name=".$_POST['name']."&email=".$_POST['email']."&comment=".$_POST['comment']);

exit();
}


Don Wieland
D W   D a t a   C o n c e p t s
~~~~~~~~~~~~~~~~~~~~~~~~~
d...@dwdataconcepts.com
Direct Line - (949) 305-2771

Integrated data solutions to fit your business needs.

Need assistance in dialing in your FileMaker solution? Check out our
Developer Support Plan at:
http://www.dwdataconcepts.com/DevSup.html

Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9
or higher
http://www.appointment10.com

For a quick overview -
http://www.appointment10.com/Appt10_Promo/Overview.html


You still haven't given us what ERROR you receive, but you need to
urlencode() $_POST['comment'] and the other values in the URL query string.


echo "HI";
header(...

This part will cause an error since outputting anything will cause the headers to be sent (unless output buffering is on). Once sent, the headers cannot be modified.

You should also think about using urlencode on the values being sent in the redirect URLs, or even using a code to reference each error.
--- End Message ---
--- Begin Message ---
Hello,

I'm trying to access (from CLI) some website, where login is required.
Please, is it possible to set/save some cookies first (login session
information) and then access the website as logged user? All through CLI.

 

Thank you very much for any information.

 

David Cesal


--- End Message ---
--- Begin Message ---
On Sun, 2010-06-13 at 16:58 +0200, David Česal wrote:

> Hello,
> 
> I'm trying to access (from CLI) some website, where login is required.
> Please, is it possible to set/save some cookies first (login session
> information) and then access the website as logged user? All through CLI.
> 
>  
> 
> Thank you very much for any information.
> 
>  
> 
> David Cesal
> 


I don't believe cookies are available in a CLI script, they are a
construct of the browser/web server setup. Running PHP via the command
line is just like any other script over the command line.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On 06/13/2010 09:58 AM, David Česal wrote:
> Hello,
> 
> I'm trying to access (from CLI) some website, where login is required.
> Please, is it possible to set/save some cookies first (login session
> information) and then access the website as logged user? All through CLI.
> 
>  
> 
> Thank you very much for any information.
> 
>  
> 
> David Cesal
> 
> 

I'm almost positive you can do this with cURL and it should be fairly
simple.  Check it out.

http://php.net/manual/en/book.curl.php

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
Hello List.

I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following:

$thepath = parse_url($url);


Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows:

/mydirectory/mysubdirectory/anothersubdirectory/mypage.php

vs.

/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the variables equal the following

$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable.

 Thanks for any help.

 --Rick



--- End Message ---
--- Begin Message ---
On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:

> Hello List.
> 
> I need to parse the PATH portion of URL.  I have assigned the path  
> portion to a variable using the following:
> 
> $thepath = parse_url($url);
> 
> 
> Now I need to break each portion of the path down into its own  
> variable.  The problem is, the path can vary considerably as follows:
> 
> /mydirectory/mysubdirectory/anothersubdirectory/mypage.php
> 
> vs.
> 
> /mydirectory/mypage.php
> 
> How do I get the either of the above url paths broken out so the  
> variables equal the following
> 
> $dir1 = mydirectory
> $dir2 = mysubdirectory
> $dir3 = anothersubdirectory
> $page = mypage.php
> 
> ...etc... if there were 5 more subdirectories... they would be  
> dynamically assigned to a variable.
> 
>   Thanks for any help.
> 
>   --Rick
> 
> 
> 


$filename = basename($path);
$parts = explode('/', $path);
$directories = array_pop($parts);

Now you have your directories in the $directories array and the filename
in $filename.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---

On Jun 13, 2010, at 5:13 PM, Rick Dwyer wrote:

Hello List.

I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following:

$thepath = parse_url($url);


Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows:

/mydirectory/mysubdirectory/anothersubdirectory/mypage.php

vs.

/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the variables equal the following

$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable.

 Thanks for any help.

 --Rick



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Hi Rick,

Just a thought, but cant you do something to separate them according to the "/" (forward slash)?
maybe preg_replace or something. Sorry not much more help.


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--- End Message ---
--- Begin Message ---

On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote:

On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:

Hello List.

I need to parse the PATH portion of URL.  I have assigned the path
portion to a variable using the following:

$thepath = parse_url($url);


Now I need to break each portion of the path down into its own
variable.  The problem is, the path can vary considerably as follows:

/mydirectory/mysubdirectory/anothersubdirectory/mypage.php

vs.

/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the
variables equal the following

$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be
dynamically assigned to a variable.

  Thanks for any help.

  --Rick





$filename = basename($path);
$parts = explode('/', $path);
$directories = array_pop($parts);

Now you have your directories in the $directories array and the filename
in $filename.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Hi Ash,
What about the "//" in  the beginning?


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--- End Message ---
--- Begin Message ---
On Sun, 2010-06-13 at 17:27 -0500, Karl DeSaulniers wrote:

> On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote:
> 
> > On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:
> >
> >> Hello List.
> >>
> >> I need to parse the PATH portion of URL.  I have assigned the path
> >> portion to a variable using the following:
> >>
> >> $thepath = parse_url($url);
> >>
> >>
> >> Now I need to break each portion of the path down into its own
> >> variable.  The problem is, the path can vary considerably as follows:
> >>
> >> /mydirectory/mysubdirectory/anothersubdirectory/mypage.php
> >>
> >> vs.
> >>
> >> /mydirectory/mypage.php
> >>
> >> How do I get the either of the above url paths broken out so the
> >> variables equal the following
> >>
> >> $dir1 = mydirectory
> >> $dir2 = mysubdirectory
> >> $dir3 = anothersubdirectory
> >> $page = mypage.php
> >>
> >> ...etc... if there were 5 more subdirectories... they would be
> >> dynamically assigned to a variable.
> >>
> >>   Thanks for any help.
> >>
> >>   --Rick
> >>
> >>
> >>
> >
> >
> > $filename = basename($path);
> > $parts = explode('/', $path);
> > $directories = array_pop($parts);
> >
> > Now you have your directories in the $directories array and the  
> > filename
> > in $filename.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> 
> 
> Hi Ash,
> What about the "//" in  the beginning?
> 
> 
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
> 
> 


As your example string didn't have a double slash I didn't write code
for that, but it's easy enough to remove 0-length strings from the
$directories array.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---

On Jun 13, 2010, at 5:31 PM, Ashley Sheridan wrote:

On Sun, 2010-06-13 at 17:27 -0500, Karl DeSaulniers wrote:

On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote:

On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:

Hello List.

I need to parse the PATH portion of URL.  I have assigned the path
portion to a variable using the following:

$thepath = parse_url($url);


Now I need to break each portion of the path down into its own
variable. The problem is, the path can vary considerably as follows:

/mydirectory/mysubdirectory/anothersubdirectory/mypage.php

vs.

/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the
variables equal the following

$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be
dynamically assigned to a variable.

  Thanks for any help.

  --Rick





$filename = basename($path);
$parts = explode('/', $path);
$directories = array_pop($parts);

Now you have your directories in the $directories array and the
filename
in $filename.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Hi Ash,
What about the "//" in  the beginning?


Karl DeSaulniers
Design Drumm
http://designdrumm.com




As your example string didn't have a double slash I didn't write code
for that, but it's easy enough to remove 0-length strings from the
$directories array.

Thanks,
Ash
http://www.ashleysheridan.co.uk



:) Rick's example, but how in your example do we look for a double forward slash?
THX

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--- End Message ---
--- Begin Message ---
OK, I get the following error:

Warning: basename() expects parameter 1 to be string, array given in....

When I use the following:

$thepath = parse_url($url);
$filename = basename($thepath);

Is my variable thepath not automatically string?

 --Rick


On Jun 13, 2010, at 6:23 PM, Ashley Sheridan wrote:

On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:

Hello List.

I need to parse the PATH portion of URL.  I have assigned the path
portion to a variable using the following:

$thepath = parse_url($url);


Now I need to break each portion of the path down into its own
variable.  The problem is, the path can vary considerably as follows:

/mydirectory/mysubdirectory/anothersubdirectory/mypage.php

vs.

/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the
variables equal the following

$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be
dynamically assigned to a variable.

  Thanks for any help.

  --Rick




$filename = basename($path);
$parts = explode('/', $path);
$directories = array_pop($parts);

Now you have your directories in the $directories array and the filename in $filename.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---

On Jun 13, 2010, at 5:35 PM, Rick Dwyer wrote:

OK, I get the following error:

Warning: basename() expects parameter 1 to be string, array given in....

When I use the following:

$thepath = parse_url($url);
$filename = basename($thepath);

Is my variable thepath not automatically string?

 --Rick



try echo($url); and see


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--- End Message ---
--- Begin Message ---
On Sun, 2010-06-13 at 17:35 -0500, Karl DeSaulniers wrote:

> On Jun 13, 2010, at 5:31 PM, Ashley Sheridan wrote:
> 
> > On Sun, 2010-06-13 at 17:27 -0500, Karl DeSaulniers wrote:
> >
> >> On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote:
> >>
> >>> On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:
> >>>
> >>>> Hello List.
> >>>>
> >>>> I need to parse the PATH portion of URL.  I have assigned the path
> >>>> portion to a variable using the following:
> >>>>
> >>>> $thepath = parse_url($url);
> >>>>
> >>>>
> >>>> Now I need to break each portion of the path down into its own
> >>>> variable.  The problem is, the path can vary considerably as  
> >>>> follows:
> >>>>
> >>>> /mydirectory/mysubdirectory/anothersubdirectory/mypage.php
> >>>>
> >>>> vs.
> >>>>
> >>>> /mydirectory/mypage.php
> >>>>
> >>>> How do I get the either of the above url paths broken out so the
> >>>> variables equal the following
> >>>>
> >>>> $dir1 = mydirectory
> >>>> $dir2 = mysubdirectory
> >>>> $dir3 = anothersubdirectory
> >>>> $page = mypage.php
> >>>>
> >>>> ...etc... if there were 5 more subdirectories... they would be
> >>>> dynamically assigned to a variable.
> >>>>
> >>>>   Thanks for any help.
> >>>>
> >>>>   --Rick
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>> $filename = basename($path);
> >>> $parts = explode('/', $path);
> >>> $directories = array_pop($parts);
> >>>
> >>> Now you have your directories in the $directories array and the
> >>> filename
> >>> in $filename.
> >>>
> >>> Thanks,
> >>> Ash
> >>> http://www.ashleysheridan.co.uk
> >>>
> >>>
> >>
> >>
> >> Hi Ash,
> >> What about the "//" in  the beginning?
> >>
> >>
> >> Karl DeSaulniers
> >> Design Drumm
> >> http://designdrumm.com
> >>
> >>
> >
> >
> > As your example string didn't have a double slash I didn't write code
> > for that, but it's easy enough to remove 0-length strings from the
> > $directories array.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> 
> :) Rick's example, but how in your example do we look for a double  
> forward slash?
> THX
> 
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
> 
> 


You don't look for one, that's the point. The explode() breaks the
string into an array at every occurrence of a '/' character. This will
leave zero length strings in the array if there is a double // (which
wasn't in any given example in this thread that I saw) When you use the
array, just don't do anything with empty elements!

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---

On Jun 13, 2010, at 5:35 PM, Rick Dwyer wrote:

OK, I get the following error:

Warning: basename() expects parameter 1 to be string, array given in....

When I use the following:

$thepath = parse_url($url);
$filename = basename($thepath);

Is my variable thepath not automatically string?

 --Rick

Oops I meant
echo($the_path);
or echo both and see.


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--- End Message ---
--- Begin Message ---
On Sun, 2010-06-13 at 18:35 -0400, Rick Dwyer wrote:

> OK, I get the following error:
> 
> Warning: basename() expects parameter 1 to be string, array given in....
> 
> When I use the following:
> 
> $thepath = parse_url($url);
> $filename = basename($thepath);
> 
> Is my variable thepath not automatically string?
> 
>   --Rick
> 
> 
> On Jun 13, 2010, at 6:23 PM, Ashley Sheridan wrote:
> 
> > On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:
> >>
> >> Hello List.
> >>
> >> I need to parse the PATH portion of URL.  I have assigned the path
> >> portion to a variable using the following:
> >>
> >> $thepath = parse_url($url);
> >>
> >>
> >> Now I need to break each portion of the path down into its own
> >> variable.  The problem is, the path can vary considerably as follows:
> >>
> >> /mydirectory/mysubdirectory/anothersubdirectory/mypage.php
> >>
> >> vs.
> >>
> >> /mydirectory/mypage.php
> >>
> >> How do I get the either of the above url paths broken out so the
> >> variables equal the following
> >>
> >> $dir1 = mydirectory
> >> $dir2 = mysubdirectory
> >> $dir3 = anothersubdirectory
> >> $page = mypage.php
> >>
> >> ...etc... if there were 5 more subdirectories... they would be
> >> dynamically assigned to a variable.
> >>
> >>   Thanks for any help.
> >>
> >>   --Rick
> >>
> >>
> >>
> >
> > $filename = basename($path);
> > $parts = explode('/', $path);
> > $directories = array_pop($parts);
> >
> > Now you have your directories in the $directories array and the  
> > filename in $filename.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> 
> 


Because you've given it an array. Your original question never mentioned
you were using parse_url() on the original array string. parse_url()
breaks the string into its component parts, much like my explode
example.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---

On Jun 13, 2010, at 5:40 PM, Ashley Sheridan wrote:

On Sun, 2010-06-13 at 17:35 -0500, Karl DeSaulniers wrote:

On Jun 13, 2010, at 5:31 PM, Ashley Sheridan wrote:

> On Sun, 2010-06-13 at 17:27 -0500, Karl DeSaulniers wrote:
>
>> On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote:
>>
>>> On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:
>>>
>>>> Hello List.
>>>>
>>>> I need to parse the PATH portion of URL. I have assigned the path
>>>> portion to a variable using the following:
>>>>
>>>> $thepath = parse_url($url);
>>>>
>>>>
>>>> Now I need to break each portion of the path down into its own
>>>> variable.  The problem is, the path can vary considerably as
>>>> follows:
>>>>
>>>> /mydirectory/mysubdirectory/anothersubdirectory/mypage.php
>>>>
>>>> vs.
>>>>
>>>> /mydirectory/mypage.php
>>>>
>>>> How do I get the either of the above url paths broken out so the
>>>> variables equal the following
>>>>
>>>> $dir1 = mydirectory
>>>> $dir2 = mysubdirectory
>>>> $dir3 = anothersubdirectory
>>>> $page = mypage.php
>>>>
>>>> ...etc... if there were 5 more subdirectories... they would be
>>>> dynamically assigned to a variable.
>>>>
>>>>   Thanks for any help.
>>>>
>>>>   --Rick
>>>>
>>>>
>>>>
>>>
>>>
>>> $filename = basename($path);
>>> $parts = explode('/', $path);
>>> $directories = array_pop($parts);
>>>
>>> Now you have your directories in the $directories array and the
>>> filename
>>> in $filename.
>>>
>>> Thanks,
>>> Ash
>>> http://www.ashleysheridan.co.uk
>>>
>>>
>>
>>
>> Hi Ash,
>> What about the "//" in  the beginning?
>>
>>
>> Karl DeSaulniers
>> Design Drumm
>> http://designdrumm.com
>>
>>
>
>
> As your example string didn't have a double slash I didn't write code
> for that, but it's easy enough to remove 0-length strings from the
> $directories array.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>

:) Rick's example, but how in your example do we look for a double
forward slash?
THX

Karl DeSaulniers
Design Drumm
http://designdrumm.com



You don't look for one, that's the point. The explode() breaks the string into an array at every occurrence of a '/' character. This will leave zero length strings in the array if there is a double // (which wasn't in any given example in this thread that I saw) When you use the array, just don't do anything with empty elements!

Thanks,
Ash
http://www.ashleysheridan.co.uk




Ahh.. that makes sense. Thanks Ash.


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--- End Message ---
--- Begin Message ---
OK, sorry for any confusion.

Here is all my code:

$url = "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://". $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$thepath = parse_url($url);

So, given that the URL can vary as follows:

/mydirectory/mysubdirectory/anothersubdirectory/mypage.php
vs.
/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the variables equal the following

$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable.

 --Rick





On Jun 13, 2010, at 6:42 PM, Ashley Sheridan wrote:

On Sun, 2010-06-13 at 18:35 -0400, Rick Dwyer wrote:

OK, I get the following error:

Warning: basename() expects parameter 1 to be string, array given in....

When I use the following:

$thepath = parse_url($url);
$filename = basename($thepath);

Is my variable thepath not automatically string?

 --Rick


On Jun 13, 2010, at 6:23 PM, Ashley Sheridan wrote:

On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:

Hello List.

I need to parse the PATH portion of URL.  I have assigned the path
portion to a variable using the following:

$thepath = parse_url($url);


Now I need to break each portion of the path down into its own
variable. The problem is, the path can vary considerably as follows:

/mydirectory/mysubdirectory/anothersubdirectory/mypage.php

vs.

/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the
variables equal the following

$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be
dynamically assigned to a variable.

 Thanks for any help.

 --Rick




$filename = basename($path);
$parts = explode('/', $path);
$directories = array_pop($parts);

Now you have your directories in the $directories array and the
filename in $filename.

Thanks,
Ash
http://www.ashleysheridan.co.uk






Because you've given it an array. Your original question never mentioned
you were using parse_url() on the original array string. parse_url()
breaks the string into its component parts, much like my explode
example.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---

Reply via email to