php-general Digest 17 Oct 2005 10:35:46 -0000 Issue 3742
Topics (messages 224207 through 224218):
Funky array question
224207 by: Brian Dunning
224209 by: Minuk Choi
224210 by: Jordan Miller
224211 by: Jordan Miller
224212 by: Jordan Miller
Re: editor
224208 by: yangshiqi1089
a couple of problems with PHP form
224213 by: Bruce Gilbert
224218 by: Mark Rees
Re: OPTIMIZING - The fastest way to open and show a file
224214 by: Ruben Rubio Rey
224215 by: Ruben Rubio Rey
224216 by: ac
can't get IIS to run php if the script is not directly under wwwroot
224217 by: tony yau
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 ---
I want to create an array like this:
$myArray=array(
array('orange','A very bright color'),
array('blue','A nice color like the ocean'),
array('yellow','Very bright like the sun') ...etc...
)
Sort of like a small database in memory. Then I want to compare each
of the rows coming out of a MySQL call, which are sentences, against
this array to see if the FIRST TERM in each array element is present
in the sentence, and then display the SECOND TERM from the array for
each sentence. Make sense? So for these two sentences, and the above
array, here's how I want it to output:
"He used blue paint" - A nice color like the ocean.
"The flower was yellow" - Very bright like the sun.
Can someone help me out with the code needed to search the sentence
to which FIRST TERM appears in it, and retrieve the SECOND TERM? I've
tried too many things and now my brain is tied in a knot.
--- End Message ---
--- Begin Message ---
Assuming that you are also accepting partial matches... (e.g. if you had
a sentence with something like, "Mr. LeBlue says hello", and
that should be a match for "blue")
If $mysqlString contains 1 sentence from the mySQL database(I assume
you've a loop or something that'll fetch 1 string per iteration)
$resultStr = $mysqlString;
$bFound=false;
foreach ($myArray as $colorArray)
{
$firstTerm = $colorArray[0];
$secondTerm = $colorArray[1];
if (strpos($resultStr, $firstTerm)!==false)
{
$resultStr = $secondTerm;
$bFound=true;
}
if ($bFound)
break;
}
$mysqlString = $resultStr;
Try that.
Brian Dunning wrote:
I want to create an array like this:
$myArray=array(
array('orange','A very bright color'),
array('blue','A nice color like the ocean'),
array('yellow','Very bright like the sun') ...etc...
)
Sort of like a small database in memory. Then I want to compare each
of the rows coming out of a MySQL call, which are sentences, against
this array to see if the FIRST TERM in each array element is present
in the sentence, and then display the SECOND TERM from the array for
each sentence. Make sense? So for these two sentences, and the above
array, here's how I want it to output:
"He used blue paint" - A nice color like the ocean.
"The flower was yellow" - Very bright like the sun.
Can someone help me out with the code needed to search the sentence
to which FIRST TERM appears in it, and retrieve the SECOND TERM? I've
tried too many things and now my brain is tied in a knot.
--- End Message ---
--- Begin Message ---
Hello,
what have you been trying for comparison so far that has not been
working?
if you have php 5, you would want to use stripos, which is case-
INsensitive, not strpos, which is the opposite.
Also, note the warning on the man page. you would want to use a
triple equals sign "!===false" because stripos could return a zero or
an empty string which is actually "==false".
http://www.php.net/stripos/
if you do not have php 5, i would use regex so you can get case
insensitivity.
Jordan
On Oct 16, 2005, at 11:18 PM, Minuk Choi wrote:
Assuming that you are also accepting partial matches... (e.g. if
you had a sentence with something like, "Mr. LeBlue says hello", and
that should be a match for "blue")
If $mysqlString contains 1 sentence from the mySQL database(I
assume you've a loop or something that'll fetch 1 string per
iteration)
$resultStr = $mysqlString;
$bFound=false;
foreach ($myArray as $colorArray)
{
$firstTerm = $colorArray[0];
$secondTerm = $colorArray[1];
if (strpos($resultStr, $firstTerm)!==false)
{
$resultStr = $secondTerm;
$bFound=true;
}
if ($bFound)
break;
}
$mysqlString = $resultStr;
Try that.
Brian Dunning wrote:
I want to create an array like this:
$myArray=array(
array('orange','A very bright color'),
array('blue','A nice color like the ocean'),
array('yellow','Very bright like the sun') ...etc...
)
Sort of like a small database in memory. Then I want to compare
each of the rows coming out of a MySQL call, which are sentences,
against this array to see if the FIRST TERM in each array element
is present in the sentence, and then display the SECOND TERM from
the array for each sentence. Make sense? So for these two
sentences, and the above array, here's how I want it to output:
"He used blue paint" - A nice color like the ocean.
"The flower was yellow" - Very bright like the sun.
Can someone help me out with the code needed to search the
sentence to which FIRST TERM appears in it, and retrieve the
SECOND TERM? I've tried too many things and now my brain is tied
in a knot.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
sorry, I am mistaken here. I forgot that "!==" is the same
functionality as a "===", in that the comparison is made by value
*and* type.
On Oct 16, 2005, at 11:26 PM, Jordan Miller wrote:
Also, note the warning on the man page. you would want to use a
triple equals sign "!===false" because stripos could return a zero
or an empty string which is actually "==false".
--- End Message ---
--- Begin Message ---
one more thing... if you have php <5 and >= 3.0.6, you could use
stristr for case insensitive comparison without having to deal with
the slower and more cumbersome regex.
On Oct 16, 2005, at 11:18 PM, Minuk Choi wrote:
Assuming that you are also accepting partial matches... (e.g. if
you had a sentence with something like, "Mr. LeBlue says hello", and
that should be a match for "blue")
If $mysqlString contains 1 sentence from the mySQL database(I
assume you've a loop or something that'll fetch 1 string per
iteration)
$resultStr = $mysqlString;
$bFound=false;
foreach ($myArray as $colorArray)
{
$firstTerm = $colorArray[0];
$secondTerm = $colorArray[1];
if (strpos($resultStr, $firstTerm)!==false)
{
$resultStr = $secondTerm;
$bFound=true;
}
if ($bFound)
break;
}
$mysqlString = $resultStr;
Try that.
Brian Dunning wrote:
I want to create an array like this:
$myArray=array(
array('orange','A very bright color'),
array('blue','A nice color like the ocean'),
array('yellow','Very bright like the sun') ...etc...
)
Sort of like a small database in memory. Then I want to compare
each of the rows coming out of a MySQL call, which are sentences,
against this array to see if the FIRST TERM in each array element
is present in the sentence, and then display the SECOND TERM from
the array for each sentence. Make sense? So for these two
sentences, and the above array, here's how I want it to output:
"He used blue paint" - A nice color like the ocean.
"The flower was yellow" - Very bright like the sun.
Can someone help me out with the code needed to search the
sentence to which FIRST TERM appears in it, and retrieve the
SECOND TERM? I've tried too many things and now my brain is tied
in a knot.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
It's also could be vim.
-----Original Message-----
From: Hodicska Gergely [mailto:[EMAIL PROTECTED]
Sent: Saturday, October 15, 2005 9:48 PM
To: php general help
Subject: Re: [PHP] editor
>> I read somewhere about an editor, which has built in support for
>> phpdocumentator and creating unit test. Now I could not find it, I tried
>> a lot using Google without success.
> Could it be PHPEdit ?
Yes, thx, this is the editor which I tried to find. I already get it
last night, after I tried to google not "php editor unit test support",
but only "php editor simpletest".
Regards,
Felhő
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
I am trying to set up some validation for my php form with the email
field using the following code:
if(!eregi("^(.+)@(.+)\\.(.+)$",$_POST['email']))
{
$error_msg .= "<BR />Your email appears to be invalid.";
$ok = "false";
}
I am trying to accomplish not being able to enter anything other than
a valid email string
....this doesn'r seem to be doing anything.
also, I want the field to appear hilighted when there is no
information so I am doing this:
<input class="<? if($error_msg){ echo "error"; } ELSE { echo
"normal"; } id="firstname" name="firstname" type="text"
value="{$_POST['firstname']}"? />"
and I have an error class set up in my CSS, such as
.error {border: 1px solid red;}
this is not doinf anything either.
Can somone point out what may be wrong with this PHP code?
thanks,
--- End Message ---
--- Begin Message ---
-----------------------------------------------------
sorry, my editor has not indented again
-----------------------------------------------------
also, I want the field to appear hilighted when there is no
information so I am doing this:
<input class="<? if($error_msg){ echo "error"; } ELSE { echo
"normal"; } id="firstname" name="firstname" type="text"
value="{$_POST['firstname']}"? />"
and I have an error class set up in my CSS, such as
.error {border: 1px solid red;}
this is not doinf anything either.
-----------------------------------------------------
Assuming that your test for $error_msg is working correctly, change the css
definition to
input.error
-----------------------------------------------------
--- End Message ---
--- Begin Message ---
In a "almost idle desktop machine" always takes arround 0.04.
The measured is on a server when it was with low traffic (average load
arround 0.7)
ac wrote:
where did these time measured?
on a heavily loaded server or on your own almost idle desktop machine ?
On 10/14/05, Ruben Rubio Rey <[EMAIL PROTECTED]> wrote:
Hi,
I m creating a cache system, and i have a problem: PHP takes a lot of
time opening the file. (Im using 2.6.9-1.667smp and XFS)
* For files less or equal 6 Kb, takes arround 0.02-0.03 miliseconds - its
ok
* For files arround 35 Kb takes arround 0.2-0.4 miliseconds - too much.
What can I do to make faster opening files?
**************************************************************
Source code:
if(file_exists($filename)){
$modified_date=filemtime($filename);
if(time()<($modified_date+1 * 24 * 60 * 60)){
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
echo $contents;
}
}
**************************************************************
Thinks that I have tried:
* fopen is *much* faster than include
* filemtime is faster than filectime
* Pear Cache its too much slower (0.5-0.7 milsecond per file)
Thanks in advance
Tk421
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
all born, to be dying
--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
On Fri, October 14, 2005 6:29 am, Ruben Rubio Rey wrote:
if(file_exists($filename)){
$modified_date=filemtime($filename);
if(time()<($modified_date+1 * 24 * 60 * 60)){
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
echo $contents;
}
}
Checking both file_exists and then doing fopen seems a bit silly.
Trap the error from fopen, and just use that as your file_exists test.
I suspect http://php.net/file_get_contents will be SLIGHTLY faster
than doing all of this code, though:
if (filemtime($filename) > time()) $contents =
@file_get_contents($filename);
if ($contents === false){
//error-handling code
}
else{
echo $contents;
}
Then, of course, we have to wonder if you NEED $contents for later use
in the script.
If not, something like this will clock in better:
$bytes = @readfile($filename);
if ($bytes === false){
//error-handling code
}
This seems to be the best solution. I do not need $content anymore. I ll
post results. :)
The difference here is that you don't even stuff the file into the PHP
string. It's all read and passed out to stdout in low-level internal
PHP C code, and the data never needs to hit "PHP" variables which are
"more expensive" to setup and maintain.
Note that which is REALLY fastest will probably depend on the size of
the files, your OS system cache, your hardware, and maybe which
version of PHP you are using, if the underlying functions changed.
Must be nice to be worried about 0.0x milliseconds -- I'm fighting a
mystery 3.0 seconds in a data feed for a search engine myself :-)
Search engine ... thats the most complicated!
--- End Message ---
--- Begin Message ---
try `ssh' onto the server and
test locally on the server, use `wget', `curl' or even write a small script...
what do you get this time ?
low traffic may also problemical, if the server shares bandwith with
other host, and there are busy ones among them.
On 10/17/05, Ruben Rubio Rey <[EMAIL PROTECTED]> wrote:
> In a "almost idle desktop machine" always takes arround 0.04.
>
> The measured is on a server when it was with low traffic (average load
> arround 0.7)
>
> ac wrote:
>
> >where did these time measured?
> >on a heavily loaded server or on your own almost idle desktop machine ?
> >
> >
> >On 10/14/05, Ruben Rubio Rey <[EMAIL PROTECTED]> wrote:
> >
> >
> >>Hi,
> >>
> >>I m creating a cache system, and i have a problem: PHP takes a lot of
> >>time opening the file. (Im using 2.6.9-1.667smp and XFS)
> >>
> >>* For files less or equal 6 Kb, takes arround 0.02-0.03 miliseconds - its
> >>ok
> >>* For files arround 35 Kb takes arround 0.2-0.4 miliseconds - too much.
> >>
> >>What can I do to make faster opening files?
> >>
> >>**************************************************************
> >>Source code:
> >> if(file_exists($filename)){
> >> $modified_date=filemtime($filename);
> >> if(time()<($modified_date+1 * 24 * 60 * 60)){
> >> $handle = fopen($filename, "r");
> >> $contents = fread($handle, filesize($filename));
> >> fclose($handle);
> >> echo $contents;
> >> }
> >> }
> >>**************************************************************
> >>
> >>Thinks that I have tried:
> >>* fopen is *much* faster than include
> >>* filemtime is faster than filectime
> >>* Pear Cache its too much slower (0.5-0.7 milsecond per file)
> >>
> >>Thanks in advance
> >>Tk421
> >>
> >>--
> >>PHP General Mailing List (http://www.php.net/)
> >>To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >>
> >>
> >
> >
> >--
> >all born, to be dying
> >
> >
> >
> >
>
>
--
all born, to be dying
--- End Message ---
--- Begin Message ---
Can someone help please,
in w2k, when i put a test.php directly under wwwroot then it works, when i
try using a virtual directory
it fails/refused to run the script?!
any hint anyone?
--
Tony
--- End Message ---