Re: [PHP] Regular Expressions

2007-11-07 Thread Mark Summers
There was no escaping in the original either.

Also, I did assume that the list of replacements would grow to become
pretty large.  I wouldn't suggest doing this for a small list such as
that given in the example.

Robert Cummings wrote:
> On Wed, 2007-11-07 at 14:33 +0000, Mark Summers wrote:
>   
>> This is a first attempt but the general idea is that the regular
>> expression matching is done in one operation and then str_replace() is
>> called only as many times as required instead of once for every line in
>> your list.  Also, str_replace() is faster than ereg_replace().
>>
>> >
>> $replace = array(
>> "ñ" => "n",
>> "á" => "a",
>> "é" => "e",
>> "í" => "i",
>> "ó" => "o",
>> "ú" => "u"
>> );
>>
>> $link = "ssrsrsrsóererrereísddósdssú";
>>
>> if (preg_match_all("/(".join("|", array_keys($replace)).")/", $link,
>> $matches)) {
>> $matches = array_unique($matches);
>>
>> foreach ($matches[0] as $match) {
>> $link = str_replace($match, $replace[$match], $link);
>> }
>> }
>>
>> echo $link;
>>
>> ?>
>> 
>
> Don't do this, it's terribly inefficient and superfluously complicated.
> There's no escaping of the strings either before jamming them into the
> pattern. What happens if you need to replace ''.
>
> Cheers,
> Rob.
>   


Re: [PHP] Regular Expressions

2007-11-07 Thread Mark Summers
This is a much better solution.  I didn't realise that str_replace()
accepted arrays as arguments for the search and replace terms.

Mental note:  reading mailing lists backwards doesn't work.

Robert Cummings wrote:
> On Tue, 2007-11-06 at 23:24 -0300, Martin Alterisio wrote:
>   
>> 2007/11/6, Alberto García Gómez <[EMAIL PROTECTED]>:
>> 
>>> I'm a mess in regular expressions and I make this code:
>>>
>>> $link = ereg_replace('ñ','n',$link);
>>> $link = ereg_replace('á','a',$link);
>>> $link = ereg_replace('é','e',$link);
>>> $link = ereg_replace('í','i',$link);
>>> $link = ereg_replace('ó','o',$link);
>>> $link = ereg_replace('ú','u',$link);
>>>
>>> I ask if is a way to make those lines into a single one but working as
>>> well as this piece. I'm thinking in increase those lines so will be
>>> wonderful if I can optimize the code.
>>>   
>
> 
> $map = array
> (
> 'ñ', 'n',
> 'á', 'a',
> 'é', 'e',
> 'í', 'i',
> 'ó', 'o',
> 'ú', 'u',
> );
>
> $link =
> str_replace(
> array_keys( $map ), array_values( $map ), $link );
>
> ?>
>
> The only way to make it faster is to build the key array and value array
> separately, but then the association is not so clear.
>
> Cheers,
> Rob.
>   


[PHP] Annoying PHP - MySQL communication timeout

2007-11-07 Thread Mark Summers
Has anyone here experienced a problem where a MySQL server seemingly
closes a connection opened by PHP whilst the PHP script is still
running?  The problem only seems to affect scripts that run for a long
time but there are a few things that make it unusual:

1) There is no obvious correlation between the time taken for this to
happen and any of the MySQL timeout variables
2) MySQL logs nothing in its error log i.e. no "connection aborted" or
similar
3) PHP hangs indefinitely as if waiting for a response (a blocking read
according to strace) and there is no "MySQL server has gone away" or similar
4) This is not one of the numerous MySQL bugs that can be triggered
repeatedly by sending a particular SQL query
5) Calling mysql_ping() before each query attempt gives no improvement

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



Re: [PHP] Regular Expressions

2007-11-07 Thread Mark Summers
This is a first attempt but the general idea is that the regular
expression matching is done in one operation and then str_replace() is
called only as many times as required instead of once for every line in
your list.  Also, str_replace() is faster than ereg_replace().

 "n",
"á" => "a",
"é" => "e",
"í" => "i",
"ó" => "o",
"ú" => "u"
);

$link = "ssrsrsrsóererrereísddósdssú";

if (preg_match_all("/(".join("|", array_keys($replace)).")/", $link,
$matches)) {
$matches = array_unique($matches);

foreach ($matches[0] as $match) {
$link = str_replace($match, $replace[$match], $link);
}
}

echo $link;

?>

Alberto García Gómez wrote:
> I'm a mess in regular expressions and I make this code:
>
> $link = ereg_replace('ñ','n',$link); 
> $link = ereg_replace('á','a',$link);
> $link = ereg_replace('é','e',$link); 
> $link = ereg_replace('í','i',$link);
> $link = ereg_replace('ó','o',$link); 
> $link = ereg_replace('ú','u',$link);
>
> I ask if is a way to make those lines into a single one but working as well 
> as this piece. I'm thinking in increase those lines so will be wonderful if I 
> can optimize the code.
>
>
>
> Este correo ha sido enviado desde el Politécnico de Informática "Carlos Marx" 
> de Matanzas.
> "La gran batalla se librará en el campo de las ideas"
>
>   

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



Re: [PHP] Re: [PHP-DB] Re: MySQL Identifying worst-performing codes

2007-11-09 Thread Mark Summers
There may be something useful here...

http://forge.mysql.com/

chris smith wrote:
> On Nov 9, 2007 1:18 AM, Colin Guthrie <[EMAIL PROTECTED]> wrote:
>   
>> Lasitha Alawatta wrote:
>> 
>>> There is  a tool call "idera" (SQL diagnostic manager). Basically it is
>>> a performance monitoring and diagnostics tool.
>>>
>>> It has a feature;
>>> Identifying of worst-performing codes –
>>>
>>> Identifies performance bottlenecks such as the worst-performing stored
>>> procedures, long-running queries, most frequently run queries, SQL
>>> Statements and SQL batches
>>>
>>> http://www.idera.com/Products/SQLdm/Features.aspx
>>>
>>>
>>> I'm looking for a same like tool for MySQL. Is anyone have any  ideas.
>>>   
>> I know this is OT for this list but.
>>
>> In addition to the slow query logging I mentioned before (which you
>> seemed to appreciate :)), I've just stumbled across this:
>> http://rackerhacker.com/mysqltuner/
>> 
>
> http://jeremy.zawodny.com/mysql/mytop/ might come in handy too.
>
>   

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



[PHP] Loss of precision in intval()

2007-08-01 Thread Mark Summers
This sort of thing really isn't helpful...



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



Re: [PHP] Loss of precision in intval()

2007-08-01 Thread Mark Summers
I like to think that I'm reasonably aware of the limitations of floating 
point (famous last words).


To my mind, the ridiculousness (probably not a word) of the example is 
highlighted by the fact that 75.81 and 75.83 work perfectly.


Roberto Mansfield wrote:

Internally, 75.82 can't be stored exactly, so 75.82 * 100 is probably
7581.92 rather than the expected integer value of 7582. So intval is
behaving properly. Sounds like you want intval(round($a));



[EMAIL PROTECTED] wrote:
  

Very weird and counter intuitive.  Looking at the php manual, I see this:

Converting to integer from floating point:

"When converting from float to integer, the number will be rounded towards 
zero."

But you'd think the multiplication would happen before the rounding.

if you do:
$a = ceil(75.82 * 100);

you should get the proper answer.

This is what I used for testing:

\n";
echo "y is " . gettype($y) . "\n";

$a = ceil($x * $y);

echo "a is " . gettype($a) . "\n";

echo "intval(a) is " . gettype(intval($a)) . "\n";

echo $a . " *** " . intval($a);
?>

Not sure that really helps, but seems to be some kind of order of precedence 
issue.

-TG

= = = Original message = = =

This sort of thing really isn't helpful...




___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.



  


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



Re: [PHP] Why do I always come up with the hard stuff?

2007-08-07 Thread Mark Summers
Hello,

I suspect that you need to assign the new instance of mysqli to $mysqli
by reference to prevent the on-demand instance that is created by new
from being copied (cloned) at the point of assignment.

Mark

Jason Pruim wrote:
> Yes I am hijacking a thread just to screw with all the people who use
> threaded e-mail viewers and because I'm mean like that :P
>
> Figured since yall have to much time on your hands anyway I'd give you
> something else to gripe about... :)
>
> Now... My question :)
>
>  $mysqli = new mysqli("localhost", "user", "password", "database");
>
> /* check connection */
> if (mysqli_connect_errno()) {
> printf("Connect failed: %s\n", mysqli_connect_error());
> exit();
> }
>
> printf("Host information: %s\n", $mysqli->host_info);
>
> /* close connection */
> $mysqli->close();
> ?>
>
> [Tue Aug  7 11:19:20 2007] [error] PHP Fatal error:  Trying to clone
> an uncloneable object of class mysqli in
> /Volumes/RAIDer/webserver/Documents/tests/legion/mysqli.php on line 2
>
>
> What is wrong with line 2? The login info is correct since I use it to
> connect with the old mysql_connect stuff and it works just fine...
> What am I missing?
>
> --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