Re: testing string for substring
From: Agelmar (ifetteNOSPAM_at_comcast.net)
Date: 03/30/04
- Next message: Jay: "How to check an URL ..?"
- Previous message: Hayden Kirk: "New PHP 4.3.5"
- In reply to: Bart Nessux: "Re: testing string for substring"
- Next in thread: Bart Nessux: "Re: testing string for substring"
- Reply: Bart Nessux: "Re: testing string for substring"
- Reply: Bart Nessux: "Re: testing string for substring"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Mar 2004 21:52:34 -0500
Bart Nessux wrote:
> Bart Nessux wrote:
>
>> I have some php scripts that I use on several machines. Each machine
>> has an identical copy of a mysql database that the scripts run
>> against. The only differences in the DBs are the user names and
>> passwords (they all differ). Fortunately, each machine is a
>> different version of Unix or Linux, so I've instructed the script to
>> do a uname test before connecting to the local database. However, I
>> don't know how to test the variable that contains the uname string.
>>
>> $x = php_uname();
>> print $x;
>> // The print looks like this:
>> Linux localhost 2.4.22-gentoo-r5 #4 Mon Feb 2 18:28:44 EST 2004
>> i686 if ($x contains "gentoo") // How do I test this string
>> for "gentoo" {
>> connect to this db
>> }
>> else
>> ......
>
> I got this to work:
>
> $id_system = php_uname();
> if (ereg("gentoo", "$id_system", $matches))
> {
> connect to this db
> }
> ......
Do not use ereg. Ereg is doing regular expression matches, which is much
more powerful (and slower) than what you're looking for. Try simply doing
if(strstr($id_system, "gentoo"))
And btw, putting a variable in quotes is another big performance hit -
there's no need, essentially you're forcing PHP to make a string that has
the variable in it, when the variable itself is already a string in this
case.
- Next message: Jay: "How to check an URL ..?"
- Previous message: Hayden Kirk: "New PHP 4.3.5"
- In reply to: Bart Nessux: "Re: testing string for substring"
- Next in thread: Bart Nessux: "Re: testing string for substring"
- Reply: Bart Nessux: "Re: testing string for substring"
- Reply: Bart Nessux: "Re: testing string for substring"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|