php-general Digest 27 Oct 2003 04:50:51 -0000 Issue 2379

Topics (messages 167633 through 167674):

Re: How can i count time it taked to render the page?
        167633 by: Mike Brum
        167634 by: rush
        167664 by: Justin French

baffled on error_reporting
        167635 by: Gerard Samuel
        167656 by: Gerard Samuel
        167657 by: Gerard Samuel
        167658 by: Dan McCullough
        167659 by: Gerard Samuel

Parsing colorcodes
        167636 by: Simon Fredriksson
        167640 by: Burhan Khalid

Importing data into MySql via PHP
        167637 by: Mark Roberts
        167638 by: John Nichel

Strange error in PHP 4.3.4RC2
        167639 by: Fabio Rotondo
        167646 by: Evan Nemerson

Find the last friday of each month.
        167641 by: OrangeHairedBoy
        167645 by: Evan Nemerson
        167648 by: Tyler Lane
        167650 by: Bob Hockney
        167654 by: Greg Wiley
        167655 by: Bob Hockney

Re: doc_root question.
        167642 by: Burhan Khalid

Web Service in PHP/XML
        167643 by: Dan McCullough
        167651 by: Ray Hunter

XML/MySQL
        167644 by: Ian Williams
        167647 by: Evan Nemerson
        167652 by: Ray Hunter
        167653 by: Manuel Lemos
        167660 by: Raditha Dissanayake
        167673 by: Burhan Khalid

Runtime Optimization of a Parser
        167649 by: Dennis Körner

if and like together?
        167661 by: Tim Thorburn
        167662 by: Martin Towell
        167663 by: Leif K-Brooks

Re: Recommendation for Unique URL
        167665 by: Al
        167672 by: David Otton

Idea for new operator
        167666 by: Al
        167667 by: Larry E. Ullman
        167670 by: Pablo Gosse
        167674 by: Leif K-Brooks

copying a directory
        167668 by: Shawn McKenzie

GD problem
        167669 by: mantas

Re: problem in 2 dimensional Array
        167671 by: Al

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Grab the time at the beginning of the page execution and then grab the time
at the very end. Subtract the two and you have the amount of time the page
took to execute.

-M

-----Original Message-----
From: Bas [mailto:[EMAIL PROTECTED] 
Sent: Sunday, October 26, 2003 11:50 AM
To: [EMAIL PROTECTED]
Subject: [PHP] How can i count time it taked to render the page?


Any help appreciated.

Regards,

Bas

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

--- End Message ---
--- Begin Message ---
"Bas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Any help appreciated.

here is one general article about it:
http://www.phpbuilder.com/columns/akent20000926.php3

rush
--
http://www.templatetamer.com/

--- End Message ---
--- Begin Message --- You can't find out how long the pages takes to RENDER at all -- rendering is something that happens client-side.

You can find out how long it takes to execute a script (on the server), which is what I assume you mean.

See Example 1 on http://www.php.net/microtime


Justin French

--- End Message ---
--- Begin Message ---
I have a common included file with error_reporting set to 0
If I do a var_dump(error_reporting()) right after it it returns 0
In a file that includes this common file, if I var_dump(error_reporting()) 
there it return 2047, which I believe is E_ALL
It that the correct behaviour of error_reporting???
Thanks

--- End Message ---
--- Begin Message ---
On Sunday 26 October 2003 12:19 pm, Gerard Samuel wrote:
> I have a common included file with error_reporting set to 0
> If I do a var_dump(error_reporting()) right after it it returns 0
> In a file that includes this common file, if I var_dump(error_reporting())
> there it return 2047, which I believe is E_ALL
> It that the correct behaviour of error_reporting???
> Thanks

Cant say why, but after doing a fresh pull from CVS, the problem seems to have 
gone away.
Just another glitch in the Matrix...

--- End Message ---
--- Begin Message ---
On Sunday 26 October 2003 06:45 pm, Gerard Samuel wrote:
> On Sunday 26 October 2003 12:19 pm, Gerard Samuel wrote:
> > I have a common included file with error_reporting set to 0
> > If I do a var_dump(error_reporting()) right after it it returns 0
> > In a file that includes this common file, if I
> > var_dump(error_reporting()) there it return 2047, which I believe is
> > E_ALL
> > It that the correct behaviour of error_reporting???
> > Thanks
>
> Cant say why, but after doing a fresh pull from CVS, the problem seems to
> have gone away.
> Just another glitch in the Matrix...

Actually, I found the real problem.
The file that was including the common file was including it with a @ like ->
@require('./common_file.php');

Once I remove the @, the error_reporting level, reported correctly, what was 
set in the included file, so it seems that while @ turns off error reporting, 
after that point, it goes back to php.ini's default of E_ALL (2047)

Is it a bug, I have no idea at the moment.
Im currently running php 4.3.3.  Please advise.

Thanks

--- End Message ---
--- Begin Message ---
No I believe that is a feature the ability to turn off error reporting.  You
can do the same with mysql functions.

@mysql_

-----Original Message-----
From: Gerard Samuel [mailto:[EMAIL PROTECTED]
Sent: Sunday, October 26, 2003 7:04 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] baffled on error_reporting


On Sunday 26 October 2003 06:45 pm, Gerard Samuel wrote:
> On Sunday 26 October 2003 12:19 pm, Gerard Samuel wrote:
> > I have a common included file with error_reporting set to 0
> > If I do a var_dump(error_reporting()) right after it it returns 0
> > In a file that includes this common file, if I
> > var_dump(error_reporting()) there it return 2047, which I believe is
> > E_ALL
> > It that the correct behaviour of error_reporting???
> > Thanks
>
> Cant say why, but after doing a fresh pull from CVS, the problem seems to
> have gone away.
> Just another glitch in the Matrix...

Actually, I found the real problem.
The file that was including the common file was including it with a @
like ->
@require('./common_file.php');

Once I remove the @, the error_reporting level, reported correctly, what was
set in the included file, so it seems that while @ turns off error
reporting,
after that point, it goes back to php.ini's default of E_ALL (2047)

Is it a bug, I have no idea at the moment.
Im currently running php 4.3.3.  Please advise.

Thanks

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

--- End Message ---
--- Begin Message ---
On Sunday 26 October 2003 07:12 pm, Dan McCullough wrote:
> No I believe that is a feature the ability to turn off error reporting. 
> You can do the same with mysql functions.
>
> @mysql_

Yes I know about turning off error reporting, but what happens after that 
point.
An example.

-- common.php --
<?php

// php.ini error reporting is set to E_ALL

error_reporting( 0 );  // sets it to 0

var_dump(error_reporting());  // Returns 0

?>

-- foo.php --
<?php

@require('./common.php');  // Here is the problem

var_dump(error_reporting());  // Returns 2047

?>

If I remove @ from require('./common.php'); in foo.php, 
the var_dump() then correctly reports it as 0 instead of 2047

Kinda goofy if you ask me...

--- End Message ---
--- Begin Message --- Hiya fellow PHP coders!

I have a problem. I need a function to parse mIRC-colorcodes with PHP. Unfortunaly, I'm not capable to do this myself (or I'm thinking too advanced or something).

The code is built like this; chr(3) starts the color formating. After that sign, a series of numbers will come. Can be one or two digits (1-15). 0-9 can have an additional zero before it, like 00-09. Each of these number represents a color.

00 = White
01 = Black
02 = Dark Blue
03 = Dark Green
04 = Red
05 = Marron
06 = Purple
07 = Orange
08 = Yellow
09 = Green
10 = Teal
11 = Cyan
12 = Blue
13 = Magenta
14 = Dark Gray
15 = Gray

Now, to make it even worse, it's possible to use a background-color for the text. This is added with a coma. So, the syntax is "X4,8String" where X is really chr(3). Red (4) String with yellow (8) background.

The colorparsing can stop when another occurance of chr(3) commes up. Also, the colorparsing ends at the end of line.

Please help me on this issue.

//Simon
--- End Message ---
--- Begin Message --- Simon Fredriksson wrote:
Hiya fellow PHP coders!

I have a problem. I need a function to parse mIRC-colorcodes with PHP. Unfortunaly, I'm not capable to do this myself (or I'm thinking too advanced or something).

The code is built like this; chr(3) starts the color formating. After that sign, a series of numbers will come. Can be one or two digits (1-15). 0-9 can have an additional zero before it, like 00-09. Each of these number represents a color.

[ snip ]



Now, to make it even worse, it's possible to use a background-color for the text. This is added with a coma. So, the syntax is "X4,8String" where X is really chr(3). Red (4) String with yellow (8) background.



I'm not a regex guru, but |[0-9]{2},[0-9]{2}(*.?)| should capture it. I forget how to ask the regex for optional items, but that should get you started.


--
Burhan Khalid
phplist[at]meidomus[dot]com
http://www.meidomus.com

--- End Message ---
--- Begin Message ---
I haven't tried this before, but I need to now and wanted to get a couple of
pointers.

I have a client that maintains a MySql database on a webserver. They want to
import data into the database by uploading a Excel spreadsheet (most likely
saved in a .csv format). I want to import the data directly into the data
table via a php script. It appears that I should be using a LOAD DATA INFILE
command or a MYSQLIMPORT command.

>From reading documentation, it would appear the the LOAD DATA INFILE is the
way I would have to go as MYSQLIMPORT appears to be a command line only
command.

I could use some pointers from someone who has used this before....such
as...

1. What is the default file format expected? (.csv?)

2. Any quarks I would need to know about?

3. Etc...

Thanks.
Mark Roberts, Roberts Computing Systems
Webmaster Services $29.50/mo



mailto:[EMAIL PROTECTED]


--- End Message ---
--- Begin Message ---
Mark Roberts wrote:
<snip>
I have a client that maintains a MySql database on a webserver. They want to
import data into the database by uploading a Excel spreadsheet (most likely
saved in a .csv format). I want to import the data directly into the data
table via a php script. It appears that I should be using a LOAD DATA INFILE
command or a MYSQLIMPORT command.

From reading documentation, it would appear the the LOAD DATA INFILE is the
way I would have to go as MYSQLIMPORT appears to be a command line only
command.

I could use some pointers from someone who has used this before....such
as...

1. What is the default file format expected? (.csv?)

Doesn't really matter, as long as it's text/plain, and you know what the deliminter is (.csv usually is comma). It's been a long time since I used Excel, but I think you can specify the deliminter when exporting, and if that is still the case, I would go with a pipe (|). Commas are far to common in data to be used as a seperator IMHO.


2. Any quarks I would need to know about?

Not to my knowledge.


3. Etc...

No need to reinvent the wheel, check places like www.phpresourceindex.com to see if they already have a function / class to do what you need done.


Webmaster Services $29.50/mo

Do I get a cut of this? :)


--
By-Tor.com
It's all about the Rush
http://www.by-tor.com

--- End Message ---
--- Begin Message --- Hi,

I am experiencing a strange error while using PHP 4.3.4RC2.
In the apache2 log, I read:

fatal: cannot realloc() 1937201923 bytes.

I do NEVER try to allocate such memory.
I think the problem is related to some serialize/unserialize() code I am using (in fact, removing serialize/unserialize block makes the script work perfectly).
Is there anything I can do to test _exactly_ where the script bombs?


Ciao,

Fabio
--- End Message ---
--- Begin Message ---
You can try Xdebug. http://www.xdebug.org/

Can you send some code to reproduce the error?



On Sunday 26 October 2003 10:24 am, Fabio Rotondo wrote:
> Hi,
>
> I am experiencing a strange error while using PHP 4.3.4RC2.
> In the apache2 log, I read:
>
> fatal: cannot realloc() 1937201923 bytes.
>
> I do NEVER try to allocate such memory.
> I think the problem is related to some serialize/unserialize() code I am
> using (in fact, removing serialize/unserialize block makes the script
> work perfectly).
> Is there anything I can do to test _exactly_ where the script bombs?
>
> Ciao,
>
>    Fabio

-- 
Evan Nemerson
[EMAIL PROTECTED]

--
"A leader is the wave pushed ahead by the ship."

-Leo Nikolaevich Tolstoy

--- End Message ---
--- Begin Message ---
Hi all,

I'm trying to write a script to get the next last friday of the month and I
am failing miserably. It keeps giving me October 10th. So, I scrapped it.

Basically, I just want to show what the last friday of the month is, and if
that date has already passed, show the last friday of the next month.

How can I do that?

--- End Message ---
--- Begin Message ---
Search for 'doomsday algorithm' on google. Once you grok it, you should be 
able to figure out the last friday quite easily.


On Sunday 26 October 2003 11:37 am, OrangeHairedBoy wrote:
> Hi all,
>
> I'm trying to write a script to get the next last friday of the month and I
> am failing miserably. It keeps giving me October 10th. So, I scrapped it.
>
> Basically, I just want to show what the last friday of the month is, and if
> that date has already passed, show the last friday of the next month.
>
> How can I do that?

-- 
Evan Nemerson
[EMAIL PROTECTED]

--
"If you would be a real seeker after truth, you must at least once in your 
life doubt, as far as possible, all things."

-Rene Descartes

--- End Message ---
--- Begin Message --- OrangeHairedBoy wrote:

Hi all,

I'm trying to write a script to get the next last friday of the month and I
am failing miserably. It keeps giving me October 10th. So, I scrapped it.

Basically, I just want to show what the last friday of the month is, and if
that date has already passed, show the last friday of the next month.

How can I do that?



You can get the number of days in a month from date()

Now you know that the last Friday of the month will be at most 7 days from the end of the month,
loop through the last 7 days of the month and determine what date it is using the date() function.
Compare the date to determine if it is Friday or not.


And then add in the check for if the date has passed or not.
--- End Message ---
--- Begin Message ---
> OrangeHairedBoy wrote:

> >Basically, I just want to show what the last friday of the month is, and if
> >that date has already passed, show the last friday of the next month.
>
> You can get the number of days in a month from date()
> 
> Now you know that the last Friday of the month will be at most 7 days 
> from the end of the month,
> loop through the last 7 days of the month and determine what date it is 
> using  the date() function.
> Compare the date to determine if it is Friday or not.
> 
> And then add in the check for if the date has passed or not.

The last friday of the following month will be the last friday of the current 
month + the number of day in the current month > 28 ( date("t") - 28 ).

-Bob

--- End Message ---
--- Begin Message --- Evan Nemerson wrote:

Search for 'doomsday algorithm' on google. Once you grok it, you should be able to figure out the last friday quite easily.


On Sunday 26 October 2003 11:37 am, OrangeHairedBoy wrote:


Hi all,

I'm trying to write a script to get the next last friday of the month and I
am failing miserably. It keeps giving me October 10th. So, I scrapped it.

Basically, I just want to show what the last friday of the month is, and if
that date has already passed, show the last friday of the next month.

How can I do that?





Use strtotime("last Friday");

Cheers, Greg.
--- End Message ---
--- Begin Message ---
Bob wrote:

> The last friday of the following month will be the last friday of the current 
> month + the number of day in the current month > 28 ( date("t") - 28 ).

OOPS!  I meant the The last friday of the following month will be the *date* 
of the last friday of the current month MINUS the number of day in the current 
month > 28 ( date("t") - 28 ), + 7 days if not in last 7 of month.

i.e.,

Last friday of October  is 31
Last friday of November is 31 - (31 - 28) = 28.
Last friday of December is 28 - (30 - 28) = 26.
Last friday of January  is 26 - (31 - 28) = 23 + 7 = 30
    because 23rd is not in last 7.
Last friday of February is 30 - (31 - 28) = 27.
etc...

-Bob

--- End Message ---
--- Begin Message --- P M wrote:

Hello all!

I need to host several websites from the same server (physical computer), and thus require PHP to be configured for more than one directory with PHP files. Does anyone know how to specify several target directories for the doc_root directive in the configuration file?


Try Apache's VirtualHost directive.




--
Burhan Khalid
phplist[at]meidomus[dot]com
http://www.meidomus.com

--- End Message ---
--- Begin Message ---
I started writting an install script that would talk to a PHP script on one
server while being used on another.

So you would have http://www.someserver.com/install.php -->
http://www.homesever.com/install.php via CURL without the users knowledge.
The script would pass certain variables and if one didnt jive then the
install would stop and a message would be sent back.  If everything was okay
then the client would have the rest of the source ftp'd to the
http://www.someserver.com server and the install would continue until
everything was finished.  I have done very little with CURL, I'm not sure if
there are any tutorials or anything else that I could see to get some good
examples of both ends of the process anyone know of any?  Anyone know of a
better way?  I'm also looking into XML or Java on the authorization end but
not sure yet.

thanks.

dan

--- End Message ---
--- Begin Message ---
if you want to use xml and php you can use soap and then you can
incorporate other languages as well...making soap the common protocol
via http.

most languages support soap implementations of one sort.  should be
worth your time to look into soap.

--
Ray



On Sun, 2003-10-26 at 12:44, Dan McCullough wrote:
> I started writting an install script that would talk to a PHP script on one
> server while being used on another.
> 
> So you would have http://www.someserver.com/install.php -->
> http://www.homesever.com/install.php via CURL without the users knowledge.
> The script would pass certain variables and if one didnt jive then the
> install would stop and a message would be sent back.  If everything was okay
> then the client would have the rest of the source ftp'd to the
> http://www.someserver.com server and the install would continue until
> everything was finished.  I have done very little with CURL, I'm not sure if
> there are any tutorials or anything else that I could see to get some good
> examples of both ends of the process anyone know of any?  Anyone know of a
> better way?  I'm also looking into XML or Java on the authorization end but
> not sure yet.
> 
> thanks.
> 
> dan
> 
> 
> ______________________________________________________________________
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
Apologies to anyone also subscribed to php.xml.dev, who will have read this
earlier, but it doesn't seem as frequently read as this news group... so I
am reposting...


Hi
I want to write a function that will take any SQL query as a parameter, and
generate XML that represents the recordset.

e.g. "SELECT * FROM Customers"

returns:

<recordset>
    <record id="1" name="Mr Smith" purchases="2"/>
    <record id="2" name="Mr Jones" purchases="25"/>
    <record id="3" name="Mr Davis" purchases="7"/>
</recordset>

There are two approaches I think. One is to use the XML DOM, the other is
simply to join lots of strings together. What is the best approach?

Thanks (and this is my first post to a newsgroup, and my first post to this
one, so excuse me if I've missed something vital!)

cheers
ian ;-)

--- End Message ---
--- Begin Message ---
If I were you I'd just join strings- it's much less resource intensive. Just 
make sure you're using valid XML.


On Sunday 26 October 2003 12:08 pm, Ian Williams wrote:
> Apologies to anyone also subscribed to php.xml.dev, who will have read this
> earlier, but it doesn't seem as frequently read as this news group... so I
> am reposting...
>
>
> Hi
> I want to write a function that will take any SQL query as a parameter, and
> generate XML that represents the recordset.
>
> e.g. "SELECT * FROM Customers"
>
> returns:
>
> <recordset>
>     <record id="1" name="Mr Smith" purchases="2"/>
>     <record id="2" name="Mr Jones" purchases="25"/>
>     <record id="3" name="Mr Davis" purchases="7"/>
> </recordset>
>
> There are two approaches I think. One is to use the XML DOM, the other is
> simply to join lots of strings together. What is the best approach?
>
> Thanks (and this is my first post to a newsgroup, and my first post to this
> one, so excuse me if I've missed something vital!)
>
> cheers
> ian ;-)

-- 
Evan Nemerson
[EMAIL PROTECTED]

--
"The people are the only sure reliance for preservation of our liberty."

-Thomas Jefferson

--- End Message ---
--- Begin Message ---
> <recordset>
>     <record id="1" name="Mr Smith" purchases="2"/>
>     <record id="2" name="Mr Jones" purchases="25"/>
>     <record id="3" name="Mr Davis" purchases="7"/>
> </recordset>
> 
> There are two approaches I think. One is to use the XML DOM, the other is
> simply to join lots of strings together. What is the best approach?


What i have done in the past is use the dbx extension in php to do my
queries. Then i have iterated over the multi-dimensional arrays and
created xml tags with the values for the dbx result set.

You can use this type of logic with any db functions and just create xml
data.

If you have an xml record that is very specific you can use sprintf to
create something like:

$record = '<record id="%d" name="%s" purchases="%d"/>';

while( $row = database logic here ) {
  $records[] = sprintf( 
        $record, 
        $row['id'],
        $row['name'], 
        $row['purchases'] 
  );

}

Then use the array functions to merge, sort or whatever you like...

That should get you started...

HTH

--
Ray

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

On 10/26/2003 06:08 PM, Ian Williams wrote:
I want to write a function that will take any SQL query as a parameter, and
generate XML that represents the recordset.

e.g. "SELECT * FROM Customers"

returns:

<recordset>
    <record id="1" name="Mr Smith" purchases="2"/>
    <record id="2" name="Mr Jones" purchases="25"/>
    <record id="3" name="Mr Davis" purchases="7"/>
</recordset>

There are two approaches I think. One is to use the XML DOM, the other is
simply to join lots of strings together. What is the best approach?

Thank is a common problem with solutions from several people. You may find some here:


http://www.phpclasses.org/search.html?words=xml+mysql&restrict=C&go_search=1


--


Regards,
Manuel Lemos

Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--- End Message ---
--- Begin Message --- Hi,

As Ray has also mentioned sprintf() is the best approach. I would also like to point out that you would be doing three iteration over your data so please make sure that your queries are not just 'select * from customers' but 'select * from customers where something=something'

all the best


Ian Williams wrote:


Apologies to anyone also subscribed to php.xml.dev, who will have read this
earlier, but it doesn't seem as frequently read as this news group... so I
am reposting...


Hi I want to write a function that will take any SQL query as a parameter, and generate XML that represents the recordset.

e.g. "SELECT * FROM Customers"

returns:

<recordset>
   <record id="1" name="Mr Smith" purchases="2"/>
   <record id="2" name="Mr Jones" purchases="25"/>
   <record id="3" name="Mr Davis" purchases="7"/>
</recordset>

There are two approaches I think. One is to use the XML DOM, the other is
simply to join lots of strings together. What is the best approach?

Thanks (and this is my first post to a newsgroup, and my first post to this
one, so excuse me if I've missed something vital!)

cheers
ian ;-)





--
Raditha Dissanayake.
------------------------------------------------------------------------
http://www.radinks.com/sftp/          |  http://www.raditha/megaupload/
Lean and mean Secure FTP applet with  |  Mega Upload - PHP file uploader
Graphical User Inteface. Just 150 KB  |  with progress bar.

--- End Message ---
--- Begin Message --- Ian Williams wrote:

I want to write a function that will take any SQL query as a parameter, and
generate XML that represents the recordset.

If you are lucky enough to be using mysql ver 4.x+ -- it has this functionality built-in, using the --xml command line option.


Sample run :
$ mysql -u username -ppassword --xml
mysql> create table test (name text, pass text);
Query OK, 0 rows affected (0.00 sec)
mysql> insert into test (name,pass) values ('foo','secret');
Query OK, 1 row affected (0.00 sec)
mysql> select * from test;
<?xml version="1.0"?>

<resultset statement="select * from test">
  <row>
        <name>foo</name>
        <pass>secret</pass>
  </row>
</resultset>
1 row in set (0.00 sec)
mysql>

If your mysql version is < 4.x -- then you have to resort of one of the many mysql-to-xml classes available (check phpclasses.org and PEAR).

--
Burhan Khalid
phplist[at]meidomus[dot]com
http://www.meidomus.com

--- End Message ---
--- Begin Message ---
Hi,

I got a small question concerning a parser I'm working on.

While the parser goes through the text it hits different tokens, which are
the processed by functions.

There are global settings which set if a function should be called or not.
(For example one time I do not want to edit token A, the other time I only
want to edit token A).

I thought that it would be cool if the algorithm that sends the tokens to
the functions would be generated on the beginning of the script, only
putting in those functions which will be called on this specific run.

Now the main question is, is this really going to bring me a performance
tune up, or am I running for extra work that won't pay out?

Then I thought of how to implement this.
The only solution I know is creating a new script file which will be
included after it has been dynamically generated, but I guess that will be
to slow.
So is there a possibility of executing strings?
e.g. putting an if clause in a string and then executing it.

Thanks for any info...

D

--- End Message ---
--- Begin Message --- Hi,

Is there an IF LIKE statement in PHP? I've got a MySQL database setup with headings and text (think a news article site) - headings in one field, text in another. In some cases, I don't want the contents of the heading field to appear on the site - in these cases, the headings begin with 'noshow-'.

So I'm thinking the easiest way to handle this is if there is something similar to the MySQL 'LIKE' command in PHP ... is there such a beast?

TIA
-Tim

--- End Message ---
--- Begin Message ---
strstr()  and it's variants
ereg()  if you need more logic

Martin


-----Original Message-----
From: Tim Thorburn [mailto:[EMAIL PROTECTED]
Sent: Monday, 27 October 2003 12:13 PM
To: [EMAIL PROTECTED]
Subject: [PHP] if and like together?


Hi,

Is there an IF LIKE statement in PHP?  I've got a MySQL database setup with 
headings and text (think a news article site) - headings in one field, text 
in another.  In some cases, I don't want the contents of the heading field 
to appear on the site - in these cases, the headings begin with 'noshow-'.

So I'm thinking the easiest way to handle this is if there is something 
similar to the MySQL 'LIKE' command in PHP ... is there such a beast?

TIA
-Tim

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

--- End Message ---
--- Begin Message --- Tim Thorburn wrote:

Is there an IF LIKE statement in PHP? I've got a MySQL database setup with headings and text (think a news article site) - headings in one field, text in another. In some cases, I don't want the contents of the heading field to appear on the site - in these cases, the headings begin with 'noshow-'.

So I'm thinking the easiest way to handle this is if there is something similar to the MySQL 'LIKE' command in PHP ... is there such a beast?

if(preg_match('/^noshow-/', $heading)){ //Don't show }

--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
to decrypt it will be prosecuted to the full extent of the law.

--- End Message ---
--- Begin Message ---
> What is the best approach to the unique page ID? I thought I would store
the
> dept. mgrs. email address and the session ID in a db, and use the session
ID in
> the URL. Do I even need the mgr's email address? Is another approach
better?
> What have you used?

I'd concatenate the employee's email and manager's email, and then use an
MD5 hash of it as the unique string. i.e:

$unique_id = md5 ( $employee_email . $manager_email );

For more info on what MD5 is, see
http://us2.php.net/manual/en/function.md5.php

Cheers,

Al

--- End Message ---
--- Begin Message ---
On Mon, 27 Oct 2003 13:29:47 +1100, you wrote:

>> What is the best approach to the unique page ID? I thought I would store
>the
>> dept. mgrs. email address and the session ID in a db, and use the session
>ID in
>> the URL. Do I even need the mgr's email address? Is another approach
>better?
>> What have you used?
>
>I'd concatenate the employee's email and manager's email, and then use an
>MD5 hash of it as the unique string. i.e:
>
>$unique_id = md5 ( $employee_email . $manager_email );
>
>For more info on what MD5 is, see
>http://us2.php.net/manual/en/function.md5.php

Remember that there's no guarantee that any two strings won't map to the
same md5 hash, and so they are bad candidates for unique ids.

Even allowing for that, concatenating only the email addresses makes the
hash extremely vulnerable.

Better to add a salt and a timestamp, so your unique string becomes
something like:

unique_id = unix_timestamp + md5 (employee_unique_token +
manager_unique_token + random_string)

(All this assumes that you want the unique id to be unguessable for some
reason. Personally, I'd just put the primary key associated with the job in
the URL, and password-protect the site. Much simpler.)

--- End Message ---
--- Begin Message ---
Afternoon all,

Is it just me, or would everybody else like to see a case-insensitive string
comparison operator introduced into PHP? It is a type of comparison that I
use a lot, and having to strtolower() everything before comparison can
impact code readability, not to mention the angst, pain and trauma of having
to repeatedly type 'strtolower()'.

Assuming this new operator is something like '=*', the following two lines
of code would be functionally identical.

    if (strtolower($a) == strtolower($b)) echo "The same!";
    if ($a =* $b) echo "The same!";

Of course creating a new operator is only justified if the vast majority of
PHP users do these comparisons as much as I do, and are as averse to work as
I am ... :).

Thoughts?

Al

--- End Message ---
--- Begin Message ---
Is it just me, or would everybody else like to see a case-insensitive string
comparison operator introduced into PHP? It is a type of comparison that I
use a lot, and having to strtolower() everything before comparison can
impact code readability, not to mention the angst, pain and trauma of having
to repeatedly type 'strtolower()'.

I was feeling generous so I went back in time and added this functionality to PHP as of version 3. I call it the "strcasecmp" function. I placed the description and usage of the function in the PHP manual: http://www.php.net/strcasecmp


Hope you like it!
Larry

--- End Message ---
--- Begin Message ---
On Sunday, October 26, 2003 5:40 PM Al wrote:

> Is it just me, or would everybody else like to see a case-insensitive
> string comparison operator introduced into PHP?

You could use the strcasecmp() function as well:

http://ca3.php.net/manual/en/function.strcasecmp.php

<?php
$var1 = "Hello";
$var2 = "hello";
if (strcasecmp($var1, $var2) == 0) {
    echo '$var1 is equal to $var2 in a case-insensitive string
comparison';
}
?>

Cheers,
Pablo

--- End Message ---
--- Begin Message --- Larry E. Ullman wrote:

I was feeling generous so I went back in time and added this functionality to PHP as of version 3. I call it the "strcasecmp" function. I placed the description and usage of the function in the PHP manual: http://www.php.net/strcasecmp

That was nice of you, but he wanted an operator.


--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
to decrypt it will be prosecuted to the full extent of the law.

--- End Message ---
--- Begin Message ---
I need to copy a directory from one location to the other.  I didn't find a
function for this.  Is copy() supposed to work on directories as well as
files, or is there another?

TIA
-Shawn

--- End Message ---
--- Begin Message ---
Hey!
i did few upgrades on my server and i got into some weird problem.
what i did was:
Upgraded to: Apache2
Upgraded to: php 4.3.3

and after that GD stoped working...

i did check on phpinfo(); and it came up with:
gd
      GD Support  enabled
      GD Version  bundled (2.0.15 compatible)
      GIF Read Support  enabled
      PNG Support  enabled
      WBMP Support  enabled
      XBM Support  enabled


Was there any problems or anything that i missed after gd upgrade and php
upgrade? i tried to look at change log but didn't find anything that would
solve it, its just gd doesn't work and i can't fix it, php just doesn't
recognizes gd functions.
So does anybody know what problem could be? or any links that i should check
about new updates in versions?

Thanks!

mNTKz

--- End Message ---
--- Begin Message ---
> i have 2 problems in 2 dimensional array
>
> 1. how to declare global 2 dimensional array in php
> 2. how to pass 2 dimensional array in function as an
> arrgument

In the context of your questions, 2-Dimensional arrays are no different to
1-dimensional arrays.

All global vairables in PHP are stored in the predefined $GLOBALS
associative array, which is automatically global in scope. Each key of the
$GLOBALS array is a name of a global variable. For example, the following
code will print "Hello World":

<?php

    function setVarA ( $value ) {
        $GLOBALS['varA'] = $value;
    }

    function echoVarA ( ) {
        echo $GLOBALS['varA'];
    }

    $varA = "Hello";
    echoVarA( );

    setVarA ( " World");
    echo $varA;

?>

Passing an array to a function is no different passing a scalar variable:

<?php
    function countArray ( $arrayArgument ) {
        return count ($arrayArgument);
    }

    $array = array ('a', 'b');
    echo "The array has ". countArray($array) ." items.";
?>

Cheers,

Al

--- End Message ---

Reply via email to