[PHP] solution

2002-06-23 Thread Austin Marshall

I figured it out, not what i'd wanted it to be, but it works, if anyone 
can improve upon it, please let me know.

?php

function array_key_replace($foo,$original,$replacement,$replacement_value) {

 $bar=array();

 foreach($foo as $key=$value) {
 if ($key==$original) {
 $bar[$replacement]=$replacement_value;
 }
 else $bar[$key]=$value;
 }

 return $bar;

}

$foo=array(color=blue,fruit=apple,foo=bar);

$foo=array_key_replace($foo,fruit,car,pinto);

?

Enjoy! ;)

Austin W. Marshall wrote:
 I can't seem to figure out how to use array_splice to replace an element 
 while retaining the key... instead it replaces the key with 0
 
 for example...
 
 $foo=array(color=blue,fruit=apple,foo=bar);
 array_splace($foo,1,1,array(car=pinto));
 
 yields...
 
 Array
 (
[color] = blue
[0] = pinto
[foo] = bar
 )
 
 
 instead of
 
 Array
 (
[color] = blue
[car] = pinto
[foo] = bar
 )
 
 ...
 Is there a quick and dirty way to do this? or does it require chopping 
 the array up into to parts and merging them back together again.
 




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




[PHP] Re: checkboxes

2002-06-22 Thread Austin Marshall

M.E. Suliman wrote:
 Hi
 
 I know this might be a bit easy for all you experts out there.  I have
 multiple checkboxes and text areas in a form.  In the confirmation email
 sent to the user I manage to get the text areas to display in the email.
 How would I get the results of the  checkboxes to to display as well?
 
 Thanks in advance
 
 Mohamed
 
 
 

checkboxes are like any other input, yo ugive them a name and optionally 
a value, and if they are selected when the form is sent then the 
variable is set (usually to on) or given the value that you assign it.

For example: input type=checkbox name=foo value=bar would yield 
$_REQUEST['foo']==bar in the script.  Checkboxes can also use arrays, 
which usually prove to be more useful. i.e. input type=checkbox 
name=foo[apple] and input type=checkbox name=foo[banana]

Anyways, to display it in HTML it's ?=$_REQUEST['foo']? or echo 
$_REQUEST['foo']; depending on how you do things.  You can also use the 
$_POST or $_GET vars and accomplish the same thing depending on the 
mehtod you use or if register globals are on then it's just $foo;


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




[PHP] Re: Current date time in MySQL datetime format

2002-06-22 Thread Austin Marshall

Phil Schwarzmann wrote:
 I want to produce the current date  time in a MySQL datetime format
 that I can then put into a MySQL database.
 
 How do I do this?  I've tried mktime() and getdate() but it's not
 working.
 
 Thanks!!
 

If you want to do it with mysql (i.e. insert the current time) use NOW() 
(the mysql function) for example INSERT INTO foo (date) VALUES (NOW())


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




[PHP] Re: UPDATE mysql

2002-06-22 Thread Austin Marshall

Phil Schwarzmann wrote:
 I can't get UPDATE to work properly when querying MySQL.
 
 $query = UPDATE $table SET field1='$var1' WHERE id='$id';
 
 I want to update one field of one row in a table.  Is this syntax
 correct?
 

yes


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




[PHP] Re: Function needed

2002-06-09 Thread Austin Marshall

Gaylen Fraley wrote:
 I am in need of a function/script that will take a directory and search all
 filenames, recursively down, for a given file.  Can anyone point me to a
 source?  Thanks.
 
 
 

$result=`grep -r 'expression' ./`;


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




[PHP] Re: byte order of integers

2002-05-15 Thread Austin Marshall

decbin() will convert an integer to it's corresponding binary 
representation of 32 bits.  Divide that into 4 groups and you have it 
separated into bytes.

John Horton wrote:
 Hi!
 Is there any way of decomposing an integer into it's constituent bytes so
 that a new byte order can be created?
 tia
 JohnH
 
 John Horton
 Software Engineer
 BITbyBIT International Limited 
 [EMAIL PROTECTED]
 
 Tel: + 44 (0) 1865 865400 
 Fax: + 44 (0) 1865 865450
 www.bitbybit.co.uk 
 
 Disclaimer: 
 Internet communications are not secure and BitbyBit does not accept any
 legal responsibility for the content of this message.  Any views or opinions
 presented are solely those of the author and do not necessarily represent
 those of BitbyBit International Limited.  If you have received this email in
 error, please reply to the sender or call +44(0)1865 865400 and delete all
 copies of this mail.
 




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




[PHP] Re: Generate every possible combination

2002-05-15 Thread Austin Marshall

Evan Nemerson wrote:
 I need to generate every possible combination of the the values in an array. 
 For example, if...
 
 $array = Array(A, B, C);
 
 I want to be able to do something like
 
 print_r(magic_function($array));
 
 which would output
 
 Array
 (
   [0] = ABC
   [1] = ACB
   [2] = BAC
   [3] = BCA
   [4] = CAB
   [5] = CBA
 )
 
 I really have no idea where to begin. The best lead I can think of is that 
 there are going to be n! elements in the output array, where n is the size of 
 the input array.
 
 Any help would be greatly appreciated.
 
 
 Evan
 
 
 

for ($x=ord(A);$x=ord(Z);$x++)
{ for($y=ord(A);$y=ord(Z);$y++)
   { for($z=ord(A);$z=ord(Z);$z++)
 { $array[]=chr($x).chr($y).char($z);
 }
   }
}

is a quick suggestion.  Haven't tested it.



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




[PHP] Re: Generate every possible combination

2002-05-15 Thread Austin Marshall

Austin Marshall wrote:
 Evan Nemerson wrote:
 
 I need to generate every possible combination of the the values in an 
 array. For example, if...

 $array = Array(A, B, C);

 I want to be able to do something like

 print_r(magic_function($array));

 which would output

 Array
 (
 [0] = ABC
 [1] = ACB
 [2] = BAC
 [3] = BCA
 [4] = CAB
 [5] = CBA
 )

 I really have no idea where to begin. The best lead I can think of is 
 that there are going to be n! elements in the output array, where n is 
 the size of the input array.

 Any help would be greatly appreciated.


 Evan



 
 for ($x=ord(A);$x=ord(Z);$x++)
 { for($y=ord(A);$y=ord(Z);$y++)
   { for($z=ord(A);$z=ord(Z);$z++)
 { $array[]=chr($x).chr($y).char($z);
 }
   }
 }
 
 is a quick suggestion.  Haven't tested it.
 
 

never mind, wasn't paying attention.


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




[PHP] Re: forever cookie

2002-05-12 Thread Austin Marshall

Larry Linthicum wrote:
 is it possible to set a cookie that never expires?
 
 

Not really, but be realistic.  If you want a cookie that lasts longer 
than what seems reasonable give it a lifetime of a year or longer.


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




[PHP] Re: How can obtain referer's name?

2002-05-12 Thread Austin Marshall

Alex Shi wrote:
 Hi!
 
 I want to know how can a script obtain the page name where 
 it was linked. e.g., there's a link on page.html, and the link 
 points to script.php, how can script.php know the name of
 page.html? Thanks in advance for all answer!
 
 Alex

$_SERVER[HTTP_REFERER]


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




[PHP] Re: Newbie question to everybody....PHP

2002-05-11 Thread Austin Marshall

R wrote:
 Greetings people,
 Special greetings to all of you who have helped me in the past.
 
 As most of you know i am a newbie, I learned a bit of PHP via webmonkey and
 a few other places, seeing the power of PHP i decided to convert from Java
 servlets and JSP (JSP coz its expensive to host and not many hosting
 opportunities) so I baught a book called The PHP black book.
 Anyway, now that the background is done heres my questions:
 
 1)How many of you have seriously dug into arrays and has it been important
 in your programming?
 1.1)Do you think you could have done the same thing you did with arrays
 WITHOUT arrays?
 (The reason i ask this is theres a whole chapter dedicated to arrays in the
 book  its pretty frustrating)
 Last question:
 Is ther any function to make the program sleep for 10 seconds or so? or
 does anybody have a function that does this?
 
 ANY replies good,bad,flames will be welcome.
 Cheers,
 -Ryan.
 
 /* You cannot get to the top by sitting on your bottom. */
 
 
 
 

I couldn't imagine a world without arrays.  But even if you don't 
understand the creation of arrays, you should at least get familiar with 
the $_POST,$_GET,$_SERVER,etc... arrays as you probably won't be able to 
write any useful scripts without them.  Not to mention the fact that you 
will probably never be able interface with a database without using arrays.


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




[PHP] Re: an sql_layer

2002-05-11 Thread Austin Marshall

Http://Www.Promoozz.Org wrote:
 i'm sweating on this one :
 
 function sql_fetch_row($res, $nr)
 {
 global $dbtype;  
 switch ($dbtype) {   
  
 case MySQL:
 $row = mysql_fetch_row($res);
 return $row;
 break;;
 ...
 }
 
 it iz used in a php_layer.php from phpnuke, but somehow it gives errors... if i put 
a  like this:
 
 $row = mysql_fetch_row($res);
 
 i get no errors, but no result either. Where stands the  for? I can't find any info 
on thizz, what's wrong?
 
[ProMoozz signature script initiated]
  [Sharon equalzz Hitler]
 [msg written - msg read]
   [ProMoozz signature script terminated]
 http://www.kotbelasting.be - http://www.kotbelasting.be
 

First off, anyone using phpnuke is on their own, try phpnuke.org for 
help.  But an  before a function suppresses error messages, it doesn't 
make errors go away, so it's doing precisely what it is supposed to.  I 
also see two ;'s in a row, perhaps that is the problem, or perhaps the 
query was bad and that renders fetch_row useless.

We or anyone would have a far better chance of helping out if you 
explained what the error is... it will be alot easier than debunking the 
  code of phpnuke on our own.




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




[PHP] Re: Yahoo/Cobalt servers/PHP

2002-05-11 Thread Austin Marshall

Todd Cary wrote:
 One of my clients signed up for service at Yahoo for space on a Cobalt server.
 The specs say that it has Php and Interbase.  I go to the server and do a
 phpinfo() and find out that Interbase is not compiled into PHP but MySQL is.
 Then I find out that MySQL is *not* installed on the server.
 
 Am I missing something here?  If one wants to have dynamic pages and uses PHP,
 then *some* DB has to be available, correct?
 
 Todd
 
 --
 Todd Cary
 Ariste Software
 2200 D Street Extension
 Petaluma, CA 94952
 707-773-4523
 [EMAIL PROTECTED]
 
 

A DB isn't required for a dynamic site, but it certainly makes things 
easier.  But a database does not have to be installed on the server for 
you to make use of a database.  Since the mysql support is built-in, you 
can make use of the mysql_connect,mysql_query,etc... functions to 
connect to an external database.


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




[PHP] Re: Alternating table rows...

2002-05-10 Thread Austin Marshall

Glenn Sieb wrote:
 Hi everyone,
 
 I have a PHP script that reads data from an MS SQL server and outputs 
 the data into a table. I've been asked if I can alternate the colors of 
 the rows to make the report more legible. The relevant piece of code 
 looks like:
 
 for ($i = 0; $i  mssql_num_rows( $stmt ); ++$i)
  {
  $line = mssql_fetch_row($stmt);
  print (TRFONT 
 COLOR=#$colorTD$line[2]/TDTD$line[0]/TDTD$line[3]/TD/TR);
  }
 
 Is there a way for me to do one of the following:
 
 1) Test to see if $i is an even or odd number?
 2) Grab more than one line from the database at a time, and just put in 
 two table rows at once?
 
 Thanks for your help in advance!
 Glenn
 
 
 ---
 Glenn E. Sieb, System Administrator
 Lumeta Corp. mailto:[EMAIL PROTECTED]
 +1 732 357-3514 (V)
 +1 732 564-0731 (Fax)
 

$color=($i%2) ? grey : white; will let you change the background 
color depending on whether or not $i is even or odd.


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




[PHP] Re: Debugger

2002-05-10 Thread Austin Marshall

Jose Leon wrote:
 Hello:
   I have been browsing the web for a good solution to debug php code, I 
 have found several ones, but none of them meet my requeriments. I 
 create a development tool for PHP (QaDRAM Studio) and I want to be able 
 to debug php code with it, my question here is: 
 
 Why PHP 4 has no built-in debug features? This will simplify the setup 
 for debugging php code and will allow php development tools provide 
 debug support in a convenient way, instead force the user to change the 
 php.ini file to support debug and to don't be able to debug every time 
 the php version changes.
 
 I have examined DBG and it's the one that fits my needs better, but 
 there's not too much information on how to use it and what I have found 
 is not complete. Also requires to load a 'listener' to be able to debug 
 remotely. The Komodo solution looks nicer, but is propietary. Any help 
 or comments?
 
 Regards.
 
 

php -l will let you know where your syntax errors are.


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




[PHP] Re: Debugger

2002-05-10 Thread Austin Marshall

Jose Leon wrote:
php -l will let you know where your syntax errors are.
 
 
 What?
 
 Regards
 

If you invoke the interpreter from the command line (CGI).  You can use 
the -l flag to enable lint mode... that will check your script for parse 
errors.  So in a way, PHP does have a debug mode.


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




[PHP] Re: Alternating Table Rows, Part Deux..

2002-05-10 Thread Austin Marshall

Glenn Sieb wrote:
 Hey everyone!
 
 Thanks for all the hints--here's what my boss and I eventually came out 
 with:
 
 /*  ##
 ## And for every row of data we pull, we create a table row...
 ## */
 $company = 0;
 $previous = ;
 for ($i = 0; $i  mssql_num_rows( $stmt ); ++$i)
  {
  $line = mssql_fetch_row($stmt);
  $company += 
 (strcmp($previous,$line[0]) ? 1 : 0);
  $color = (($company%2) ? FF : 
 00);
  $cname = 
 (strcmp($previous,$line[0]) ? $line[0] : nbsp;);
  print (TR 
 
BGCOLOR=#$color\n\tTD$line[2]/TD\n\tTD$cname/TD\n\tTD$line[3]/TD\n/TR\n);
 
 
  $previous = $line[0];
  }
 print (/TABLE);
 
 This not only takes care of the table row colors, but also removes 
 duplicate company names so it looks MUCH neater this way :
 
 Thanks again!
 Glenn
 (who's still trying to get it all down lol.. between trying to learn 
 SQL, MySQL,PHP, PostgreSQL, and VBScript lately, I'm surprised I haven't 
 had my head explode yet!)
 
 ---
 Glenn E. Sieb, System Administrator
 Lumeta Corp. mailto:[EMAIL PROTECTED]
 +1 732 357-3514 (V)
 +1 732 564-0731 (Fax)
 

Is there not a GROUP BY clause in MS SQL?  I'm pretty sure there is.  If 
you group the query by company name then you don't have to worry about 
duplicate company names... and it will help with performance, since the 
db is optimized for that and you don't have to waste PHP to determine if 
the row is a duplicate.


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




Re: [PHP] Re: Alternating Table Rows, Part Deux..

2002-05-10 Thread Austin Marshall

Miguel Cruz wrote:
 On Fri, 10 May 2002, Austin Marshall wrote:
 
This not only takes care of the table row colors, but also removes 
duplicate company names so it looks MUCH neater this way :

Is there not a GROUP BY clause in MS SQL?  I'm pretty sure there is.  If 
you group the query by company name then you don't have to worry about 
duplicate company names... and it will help with performance, since the 
db is optimized for that and you don't have to waste PHP to determine if 
the row is a duplicate.
 
 
 But he's dealing with cases where the company name remains the same but
 other data in the row changes (for instance, a company with multiple
 offices, where you wanted to list the phone number and address for each).
 GROUP BY would discard that other data.
 
 miguel
 

Yeah, apparently i wasn't the first to not catch that either.  I realy 
should start paying attention.


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




[PHP] Re: Layout Help

2002-05-10 Thread Austin Marshall

Jason Soza wrote:
 Hey all... I really do want to thank everyone for all the help and 
 advice you give. I know my questions sometimes are probably more 
 annoying than anything else, but your input really does help.
 
 Anyway, I have a stack of 76 playlists I need to consolidate and 
 display. These are from radio shows, so each playlist has the date, the 
 name of the radio show, and anywhere from 20 - 27 tracks, artists, and 
 albums on them.
 
 I know I could simply stick these into a MySQL database using fields 
 like, date, show, track1, artist1, album1, track2, artist2, album2, 
 etc. but would that really be efficient and would I be able to use PHP 
 effectively to retrieve all that information and display it correctly?
 
 Has anyone out there done a similar project? If so, what was your 
 approach? Thanks in advance,
 
 Jason Soza
 

Using MySQL or any database for that matter will be most efficient, 
however, they way you lay it out may not be.  You'd want to store tracks 
  individually which would have columns associated with it for example, 
Artist, title, album, show date, and most importantly the playlist it is 
associated with.  You could have a seperate table for information 
specific to the playlist, so you don't have to repeat information when 
you insert songs into the track table, but isn't necessary as long as 
you maintain some consistency.

If you want to get really fancy, then you could have at least 3 tables 
like the following...

A songs table with title, author, album, song_id, where each song title 
and author combination are unique and only occur once.

A playlist table which stores the song_id in the order that is played 
and the playlist_id, the date of the show and the show_id that the 
playlist is associated with.

and a Show table which stores information specific to the show.

with three tabels you will minimize the amount of information that is 
repeated, since you'd only need to insert a particular song once, and 
build playlists from that list of songs.

The other less sexy option is to use flatfiles.  Which wouldn't be 
pretty straight forward.  Just right some information about the playlist 
at the beginning of the file in a consistent manner and fill it with 
song titles, one on each line.

I think you are on the right track with MySQL though, you just need to 
break it down to at least more than one table since having 20+ columns 
that store song names is rather ineeficient.

Hope that provides some insight.


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




[PHP] Re: MySQL or FlatFile

2002-05-10 Thread Austin Marshall

David Duong wrote:
 To store large values (100k+) and load them as much as 6+ times within the
 same hour what would be better MySql or Flatfile?
 
 

I think it really depends on the content.  If you are storing 100K+ per 
entry it sounds like it is probably something along the lines of an 
image or some other binary file.  If what you are storing is pure 
unformatted text, then i'd definitely go with MySQL, but if you are 
storing something else, like an image or an audio file, then it would be 
best to keep the files as they are and just store information about the 
files in MySQL.

A possible middle-ground (for text at least) if you want it to be 
searchable is to maintain both flatfile and mysql records.  Keep the 
flatfiels as text, untouched, but index the file and store the index 
information in MySQL.  And what i mean by indexing it is each entry into 
the database is one word only, with information about the word like the 
file it's associated with.  That way you can serve up flat files but 
search through them quite easily and won't have to dea lwith such a 
memory hog every time you make a query.


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




[PHP] Re: Any difference between these 2 forms of syntax?

2002-05-10 Thread Austin Marshall

Richard Davey wrote:
 Hi,
 
 I am wondering if there is any tangible difference between the following two
 commands:
 
 $x = $foo[status];
 $x = $foo['status'];
 
 The part in question being the use of ' or  around the status element of
 the array $foo.
 Both have the same end result in my case, I'm just purely wondering which is
 the correct form of syntax to use?
 
 Cheers,
 
 Rich
 --
 Fatal Design
 http://www.fatal-design.com
 Atari / DarkBASIC / Coding / Since 1995
 
 

It all depends on what you use as a key... you just follow the normal 
string standards.  If you want a variable evaluated within the key, then 
you must use s if you purely use text then you just need 's.

For example $x=$foo[status $y]; vs. $x=$foo['status'];


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




[PHP] Re: Any difference between these 2 forms of syntax?

2002-05-10 Thread Austin Marshall

Richard Davey wrote:
 Austin Marshall [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 
It all depends on what you use as a key... you just follow the normal
string standards.  If you want a variable evaluated within the key, then
you must use s if you purely use text then you just need 's.

For example $x=$foo[status $y]; vs. $x=$foo['status'];
 
 
 No variables included in the keys, so it looks like it's ' all the way -
 excellent, thank you.
 
 I wonder if it matters from an overhead point of view, is PHP doing more
 work than it ought to using  instead of ' because it's expecting variables?
 
 Cheers,
 
 Rich
 --
 Fatal Design
 http://www.fatal-design.com
 Atari / DarkBASIC / Coding / Since 1995
 
 

that's a possibility, but i'd suspect the overhead comes from when 
variables are actually inserted/replaced and/or characters escaped.  I 
doubt there would be much of a difference between status and 'status' 
  Nor would there be much of a diffrence between 'status '.$foo.' blah'; 
and status $foo blah;

I'd be interested to see if there were much a difference 
performance-wise though.


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




[PHP] Re: Registering an Array in a Session

2002-05-07 Thread Austin Marshall

Alexis Antonakis wrote:
 Hi,
 
 I am trying to register an array in a session, but am having no luck.
 
 
 What I have is a form with set fields on which is processed a certain number
 of times.
 
 
 Upon submitting the form each time, I run the following:
 
 session_register(fieldtext[.$page.]);
 
 where fieldtext is the name of a field on the form, and $page is the page
 number, which increases by one each time the form is submitted.
 
 
 All I get registered is the last value submitted on the form, all the
 previous values are null.
 
 Any advice would be most appreciated.
 
 TIA
 Alexis
 

Try simply registering fieldtext and refer to the array within the 
code as $fieldtext['key'];  Also, if you are using a recent version of 
PHP, there is no need to register session variables.  You can make use 
of $_SESSION and store arrays within it, for example 
$_SESSION['fieldtext']['key'];


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




[PHP] Re: how to generate a date between 1998 and today by random?

2002-05-07 Thread Austin Marshall

Try making use of a timestamp via the strtotime.  You'll have to do the 
math, but you can generate a random number with the range being the 
number of seconds in the date range and then adding the remaining 
offset.  Then convert the timestamp back to a date with everyones 
favorite date() function.

Andy wrote:
 hi there,
 
 I am wondering if there is an easy way to generate a random date. It would
 work by creating arrays of values and then just selecting like:
 
 $year = array(2002, 2003, 2004, 2005);
 $month = array
 ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Okt','Nov','Dez');
 
 $date = $month[rand(0,count($month))].' '.rand(0,31).',
 '.$year[rand(0,count($year))];
 
 But there might be an easyer and faster (better performant) way.
 
 Thanx for any help,
 
 Andy
 
 




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




[PHP] Re: newbie needs help with array-checking

2002-05-07 Thread Austin Marshall

Moritz Helten wrote:
 Hello,
 
 I have a problem with checking an array if it is empty:
 
 if ($artikel[$i] != ){
 ...
 }
 
 That code does not work!
 
 May somebody help me?
 
 thanx,
 Moritz
 
 

take a look at the manual... there is a empty() function that checks for 
this very thing.


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




[PHP] Re: parsing HTML text

2002-05-07 Thread Austin Marshall

Lee Doolan wrote:
 
 I have written form screen which has as one of it's elements a
 textarea box in which a user can input some text --like a simple
 bio-- which will appear on another screen.  I'd like to edit check
 this text. It would be a good idea to make sure that it has, among other
 things, no form elements, say, or to make sure that if a font
 tag occurs, that a matching /font tag is present.
 
 Is anyone aware of a  class or a package which I can use to parse this
 text and do this kind of validation?
 
 tia
 -lee
 

strip_tags() is your friend, http://www.php.net/strip_tags


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




[PHP] Re: pass. vars. betn. javascript and php

2002-05-06 Thread Austin Marshall

Pushkar Pradhan wrote:
 Is it possible to pass variables from a php page to a page using
 javascript, and vice versa,
 I've the variable - an array passed in the url of the page.
 
 -Pushkar S. Pradhan
 

Yes and no. You can pass variables to a php script with the normal HTTP 
POST ang GET methods, however it's done with javascript.


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




[PHP] Re: sum

2002-05-06 Thread Austin Marshall

Mike Fifield wrote:
 I am using the mysql sum() function to return the sum of a bunch of dolor
 amounts stored  float values. But what I get back it something like this
 98.18855591 it is to precise. All I want is the dolor amounts added up
 and rounded up to the closest penny. Is there a better value type to use or
 a function that will return the information properly formatted. 
  
 Mike Fifield
 Charles Schwab  Co, Inc.
 WARNING: All e-mail sent to or from this address will be received by the
 Charles Schwab corporate e-mail system and is subject to archival and review
 by someone other than the recipient.
  
 

MySQL has a decimal column type which allows you to specify to how many 
decimal points the number is stored. 
http://www.mysql.com/doc/C/o/Column_types.html

If you want to do it via PHP, you can format the number via 
number_format() and that will give you the 2 decimal points as well as 
the commas where needed.

Also, both PHP and MySLQ have round() functions to format the numbers.


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




[PHP] Re: Making a Client-side HTTPS Request

2002-05-06 Thread Austin Marshall

Jonathan Rosenberg wrote:
 I would like to be able to make a client side HTTPS request from
 one of my pages.  From searching around, I see that I can do
 everything I want using the CURL library.  But the ISP I am using
 does not have the CURL library installed.
 
 I'll ask them if they'll install this library.  But, assuming
 they don't, do I have any other options for doing what I want?
 
 --
 JR
 

Even if they don't have it compiled into PHP, they might have curl 
installed and available from the command line.


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




Re: [PHP] Re: Making a Client-side HTTPS Request

2002-05-06 Thread Austin Marshall

What i meant was the actual curl application is installed on the server. 
  Accessible from the command line at, for example, /usr/local/bin/curl

With PHP you can execute commands via the command line via system(), 
exec() or via the backtick (for example $output=`/usr/local/bin/curl 
request`;) operator.

You also might be able to load the extension via dl() and compile it on 
your own, but i wouldn't recommend that.

First try the command line option, then ask your ISP to install then 
extension.

Jonathan Rosenberg wrote:
 I'm quite new to PHP (though I have lots of programming
 experience, web  otherwise).
 
 Where can I learn more about what installed and available from
 the command line means?
 
 
-Original Message-
From: Austin Marshall [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 06, 2002 1:19 PM
To: Jonathan Rosenberg
Cc: [EMAIL PROTECTED]
Subject: [PHP] Re: Making a Client-side HTTPS Request


Jonathan Rosenberg wrote:

I would like to be able to make a client side HTTPS

request from

one of my pages.  From searching around, I see that I can do
everything I want using the CURL library.  But the

ISP I am using

does not have the CURL library installed.

I'll ask them if they'll install this library.  But, assuming
they don't, do I have any other options for doing

what I want?

--
JR


Even if they don't have it compiled into PHP, they
might have curl
installed and available from the command line.


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


 
 




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




Re: [PHP] Re: Making a Client-side HTTPS Request

2002-05-06 Thread Austin Marshall

Yeah, you can download and install it within your home directory and 
call it from there.  As far as permissions go, chmod a+x curl should 
do it.

Jonathan Rosenberg wrote:
 AHhh ... got it.  If my ISP won't install CURL  they don't have
 the application, can I download binaries to my directory 
 execute it from there using PHP?  or, does the executable have to
 run with special permissions?
 
 
-Original Message-
From: Austin Marshall [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 06, 2002 1:35 PM
To: Jonathan Rosenberg
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: Making a Client-side HTTPS Request


What i meant was the actual curl application is
installed on the server.
  Accessible from the command line at, for example,
/usr/local/bin/curl

With PHP you can execute commands via the command line
via system(),
exec() or via the backtick (for example
$output=`/usr/local/bin/curl
request`;) operator.

You also might be able to load the extension via dl()
and compile it on
your own, but i wouldn't recommend that.

First try the command line option, then ask your ISP
to install then
extension.

Jonathan Rosenberg wrote:

I'm quite new to PHP (though I have lots of programming
experience, web  otherwise).

Where can I learn more about what installed and

available from

the command line means?



-Original Message-
From: Austin Marshall [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 06, 2002 1:19 PM
To: Jonathan Rosenberg
Cc: [EMAIL PROTECTED]
Subject: [PHP] Re: Making a Client-side HTTPS Request


Jonathan Rosenberg wrote:


I would like to be able to make a client side HTTPS

request from


one of my pages.  From searching around, I see that I can do
everything I want using the CURL library.  But the

ISP I am using


does not have the CURL library installed.

I'll ask them if they'll install this library.

But, assuming

they don't, do I have any other options for doing

what I want?


--
JR


Even if they don't have it compiled into PHP, they
might have curl
installed and available from the command line.


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







 




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




[PHP] Re: Sorting, sort of

2002-05-06 Thread Austin Marshall

Jason Soza wrote:
 I have a 'name' field in a MySQL table that contains people's first and 
 last names, i.e. John Smith - but some people may choose not to 
 include their last name, so they're just John in the table, or they 
 may choose to include themselves and someone else, but not the last 
 name, John and Jane.
 
 I'm thinking the easiest way to sort by last name, which is what I want 
 to do, is to just go into MySQL and make 'first_name' and 'last_name' 
 fields, but if there's a way to do this with PHP that'd be great, so 
 then I wouldn't have to mess with the table and data.
 
 Anyhow, I've looked up sort() and asort() in the PHP manual, but I'm 
 not sure how I'd go about this. I assume I'd use some kind of function 
 to read the 'name' field to the first space, take what it finds after 
 the space and put it into an array, then have some if/else statement to 
 deal with the lack of a space or the presence of multiple spaces, then 
 use sort() on that array. 
 
 Just looking for some guidance, maybe a specific function or bit of 
 code. Anything that'd help. Or if this would be more easily addressed 
 by reconfiguring my MySQL table, just let me know.
 
 Thanks,
 Jason Soza
 

via MySQL you can search by and order/sort by a substring'ed result.  Of 
course, when someone only puts one name or they enter multiple first 
names, it doesn't work quite the way it's supposed to.

For what i do, the following query returns the first letter of the last 
name in alphabetical order.

SELECT substring(substring_index(fullname,' ',-1),1,1)
FROM user
GROUP BY substring(substring_index(fullname,' ',-1),1,1)
ORDER by substring_index(fullname,' ',-1) ASC

There is a demo at http://www.defconzero.com/user.php?op=view

Hope that provides some insight.


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




[PHP] Re: Alternate To Making Form Variables Global (Clerified)

2002-05-06 Thread Austin Marshall

Dr. Shim wrote:
 Sorry, I'll have to clerify myself a bit. I'm rather tired. :)
 
 I have a script that verifys and inserts (into and Access databse) form
 values. I had to make the form variables global, in order to use them in
 my functions. Since the new PHP is out, the script doesn't work anymore. I
 think its probably because of the fact that I had to make those variables
 global (none of the variables are being read).
 Does any of you have an idea about how I can fix this problem? Thanks in
 advance.
 
 
 Dr. Shim [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Is there another way then to register form variables global? I just
 downloaded, and instlaled the newest version of PHP, and now my form script
 doesn't work anymore.  I had to register the form variables global in the
 script. I'm asking, is there a better way of doing this? I've herd it can
 lead to possible security hazards.
 
 Thanks for any help.
 
 
 
 

Look into the extract() function.  You could use it to turn the $_POST 
or $_GET arrays into local variables, whether you do it at the beginning 
of the script and make them global as you are currently doing or by 
doing it at the beginning of the functions that you use them, without 
globalizing anything.



For example... given the url http://localhost/foo.php?bar=banana

you'd have $_GET['bar']==banana instead of $bar==banana;

at the beginning of the script you'd have extract($_GET); and $bar would 
exist with the value banana


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




[PHP] Re: file_exists

2002-05-06 Thread Austin Marshall

Craig Westerman wrote:
 What am I doing wrong? I get parse error between first echo statement and
 else.
 
 Thanks
 
 Craig 
 [EMAIL PROTECTED]
 
 
 ?php
 $fn = image.gif;
 if (!file_exists($fn)) {
 echo img src=noimageexists.gif;
 else
 echo img src=$fn;
 }
 ?
 

You've got your semicolons in the wrong spots. Try:

?php
$fn = image.gif;
if (!file_exists($fn))
{
echo img src=noimageexists.gif;
}
else
{
echo img src=$fn;
}

?




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




Re: [PHP] file_exists

2002-05-06 Thread Austin Marshall

Craig Westerman wrote:
 I found my problem.
Try fopen() if it fails it will return false, otherwise it will return 
an integer file pointer.  You get use it to fetch files via http://, 
https://, ftp://, and more.

 
 From manual:
 file_exists() will not work on remote files; the file to be examined must
 be accessible via the server's filesystem. 
 
 File is on another server. Is there a way to check if file exists on another
 server?
 
 Craig 
 [EMAIL PROTECTED]
 
 
 -Original Message-
 From: Craig Westerman [mailto:[EMAIL PROTECTED]]
 Sent: Monday, May 06, 2002 7:58 PM
 To: php-general-list
 Subject: [PHP] file_exists
 
 
 What am I doing wrong? I get parse error between first echo statement and
 else.
 
 Thanks
 
 Craig 
 [EMAIL PROTECTED]
 
 
 ?php
 $fn = image.gif;
 if (!file_exists($fn)) {
 echo img src=noimageexists.gif;
 else
 echo img src=$fn;
 }
 ?
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 




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




Re: [PHP] global variables

2002-05-05 Thread Austin Marshall

Jule wrote:
 Hey,
 i'm just wondering if there is another way to write global variables to a 
 global.php, now i just the whole fopen etc script, where i open a file and 
 write the sctring $number_right = [whatever number it is] to the file, but is 
 there a different way to write it to the file with one simple command?
 
 i could use cookies, but i prefer a simpler way.
 
 thanks
 
 Jule

At want point did you stop and think that it would be *easier* to write 
information to a file?  You could use cookies and should use cookies if 
your looking for a simpler way, sessions as well.

If you don't mind information not being around the next time the user 
returns (after closing his/her browser) you could write to the always 
global always available $_SESSION array. For example 
$_SESSION['foo']=bar; and $_SESSION['bar']=foo;  It's not writing to 
a file, but is one simple command and the information you store will 
follow them anywhere within your site.

If you want save the information you could just as easily use $_COOKIES. 
  But would require that you use the setcookie command.


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




[PHP] Re: Php Sessions

2002-05-05 Thread Austin Marshall

Daniel SvanbäCk wrote:
 Hi
 
 I have a problem. I can't send the session_id to the next page. It worked
 before (when I had an old version of php, now I have 4.2.0). It can send the
 session_id() if it's a link, but not a header(). If it is a header I have to
 do this:
 
 define('MYSID', session_name().'='.session_id());
 header('Location: ../index.php?'.zOLSID);
 
 Do I have to add this to every header()? Or is there a easyier way. I have
 global variables = on.
 
 //Daniel
 
 

Straight from the manual at http://www.php.net/manual/en/ref.session.php

PHP is capable of doing this transparently when compiled with 
--enable-trans-sid. If you enable this option, relative URIs will be 
changed to contain the session id automatically. Alternatively, you can 
use the constant SID which is defined, if the client did not send the 
appropriate cookie. SID is either of the form session_name=session_id or 
is an empty string.

You probably didn't have --enable-trans-sid when you configured/compiled PHP


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




[PHP] Re: help!!!

2002-05-05 Thread Austin Marshall

J. H. wrote:
 Can anyone here help me write a simple auto shop
 scheduling program? Would really appreciate it if you
 would help me out. 
 
 Jane H. 
 
 __
 Do You Yahoo!?
 Yahoo! Health - your guide to health and wellness
 http://health.yahoo.com

Don't expect anyone to write your code for you.  If you come across a 
specific problem, then we may be able to help you.  If you want someone 
to write your code for you, money talks.  Hire someone.


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




[PHP] Re: mail function

2002-05-05 Thread Austin Marshall

Diana Castillo wrote:
Diana Castillo wrote:
 Hi, if I use the mail function, as in :
 mail([EMAIL PROTECTED], My Subject, Line 1\nLine 2\nLine 3);
 The mail comes from Webserver  How can I change the from ?
 
 
 
 

Just as the manual says, the 4th parameter which is optional allows you 
to specify additional headers.

Try mail([EMAIL PROTECTED], My Subject, Line 1\nLine 2\nLine 
3,From: user@domain);



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




[PHP] Re: Best BBS

2002-04-30 Thread Austin Marshall

R wrote:
 Hey all,
 
 This email is not for any questions/suggestions etc but a thank you note.
 Some time back i posted an email asking if anyone had any recomendation for
 a BBS system and I got a lot of replies.
 I thank each and every one of you who wrote in,
 after checking out the links or software names you gave me I have decided to
 use PHPBB2
 Will post a link to my site where this is installed after a week or so, tell
 me what you think.
 If you have any comments on why PHPbb2 is BAD for me lemme
 know.
 
 Cheers all  god bless.
 -Ryan.
 

To bring balance in the force, there is www.phpbb2.org.  It has a few 
arguments of why it is BAAADDD... I know i will never use phpbb2


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




Re: [PHP] PHP 4.2.0 on win2k, can't use mysql_fetch_* functions

2002-04-29 Thread Austin Marshall

1lt John W. Holmes wrote:
 Did you turn on Display_errors in php.ini?
 
 ---John Holmes...

Of Course, i think i even had it at the highest alert level.  No errors 
whatsoever, ... or die(mysql_error()) yields nothing either.

 
 - Original Message - 
 From: Austin W. Marshall [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, April 29, 2002 3:52 PM
 Subject: [PHP] PHP 4.2.0 on win2k, can't use mysql_fetch_* functions
 
 
 
Is there something about the php 4.2.0 windows binary (installer 
version) that renders the mysql_fetch_* functions useless?

I installed php 4.2.0 on windows 2000 along with Apache 1.3.24 and MySQL 
3.23.49, and in a script i have a simple SELECT statement.  The content 
is in the database, the query executes successfuly, but it's as if 
mysql_fetch_array and mysql_fetch_row functions don't return anything. 
 I know mysql support is built-in (as indicated on php.net) and working, 
because i was able to use php to insert data into the database.  On that 
one computer i was able to recreate the problem consistently and in no 
situation would mysql_fetch array or _row return anything.

I haven't had the opportunity to try this on any other win2k boxen, but 
am not having any problems in Linux or OpenBSD.  Is anyone else 
experiencing any problems?


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

 
 




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