Re: [PHP] Using PHP with MySQL - Can I supress MySQL errors?

2002-07-23 Thread Tim Fountain


On Tuesday, July 23, 2002, DonPro wrote:

> I've noticed that it there is an error performing certain commands
> like 'mysql_connect()'

> I'd like to suppress these messages as I am storing the error,
> mysql_error(), in an array. So if there is an error, I would simply
> display the contents of the array in a nice format.

Assuming I understand you correctly, to surpress errors from PHP
functions simply put an '@' symbol before the function.  This will
surpress the error message from PHP but will still execute your 'or'
statement, storing the message in your array, e.g.:

$result = @mysql_connect('blah','blah','blah') or
some_error_function();

or I guess you could also do:

$result = @mysql_connect('blah','blah','blah');
if (!$result)
{
   $error_array[] = mysql_error();
   ...
}

-- 
Tim Fountain ([EMAIL PROTECTED])
http://www.tfountain.co.uk/


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




Re: [PHP] preg_match() occurence position

2002-07-25 Thread Tim Fountain


On Thursday, July 25, 2002, Michael Sims wrote:

> On Thu, 25 Jul 2002 15:05:36 +0200, you wrote:

>> for example:
>> $mem='this is a test';
>> preg_match('/test/', ...) should return me somehow: 10

> How about this:

> $mem='this is a test';

> if(preg_match("/(.*)test/",$mem,$matches)) {
>   echo strlen($matches[1]);
> }

> Of course, if "test" occurs more than once then the above won't
> work, since regex's are "greedy"...

If you add a ? after the * then that'll make it non-greedy won't it?

-- 
Tim Fountain ([EMAIL PROTECTED])
http://www.tfountain.co.uk/


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




[PHP] Array query - finding the key for a value

2002-08-16 Thread Tim Fountain


This may be a silly question, but I'm used to being able to find PHP
functions to do whatever I want, but I can't find one to do this!

If I have an array like this:

[0] -> 'apple';
[1] -> 'pear';
[2] -> 'orange';
[3] -> 'apricot';

I know I can use in_array() to check whether, say, 'orange' is in the
array; but how do I then find out which index 'orange' is at?

-- 
Tim Fountain ([EMAIL PROTECTED])
http://www.tfountain.co.uk/


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