Re: Small problem with function..
| From: | Szii | Date: | Tue, 13 Jun 2000 16:26:35 +0000 |
| Subject: | Re: Small problem with function.. | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1726@lists.php.net to get a copy of this message | ||
Perhaps I'm incorrect about the = operator then..I'll have to double-check.
In the mean-time, you might check your
$string = substr ($string, pos + 1);
Do you mean $pos +1?
There's two places where it's used, and if you don't increment your $pos, then
your is_int ($pos) will always stay at the same place forever...
Just a thought...
-Szii
At 09:25 AM 6/13/00 +0200, Sylwester =?iso-8859-2?Q?Zar=EAbski?= wrote:
>Szii wrote:
>>
>> Sylwester Zarêbski wrote:
>> >
>> > I have problem with small function. This function doesn't work
>> >as expected, and consume all available memory and kills apache
>> >server. Here goes my function:
>> >
>> >function strdelc ( $string, $chars ) {
>> > $chars_len = strlen ( $chars );
>> > for ( $cnt = 0; $cnt < $chars_len; ++$cnt ) {
>> > $char = substr ( $chars, $cnt, 1 );
>> > while ( ( $pos = strpos ( $string, $char ) ) || is_int ( $pos ) ) {
>> > if ( $pos == 0 ) {
>> > $string = substr ( $string, pos + 1 );
>> > } elseif ( $pos < strlen ( $string ) - 1 ) {
>> > $string = substr ( $string, 0, $pos - 1 ) . substr ( $string,
pos
>> >+ 1 );
>> > } else {
>> > $string = substr ( $string, 0, $pos - 1 );
>> > }
>> > }
>> > }
>> > return ( $string );
>> >}
>> >
>> Check your "while()" conditions. Are you sure you want to be doing
>> an assignment to $pos from strpos( $string, $char)? The = will
>> ALWAYS evaluate to true (if strpos() doesn't find the string it'll return
>> FALSE and set the $pos = FALSE but the actual ASSIGNMENT works
>> successfully and therefore the statement is TRUE, and you'll hit your
>> infinite loop condition.
>
>Hmm.. i didn't know this works like that :-((
>I didn't find any word for that 'behaviour' in manual.
>I thought this works rather like C.
>But i think you're wrong..
>I observe that this loop only happens, if $string contains one of $chars..
>Then your statement about _true_assignnment_ is false..
>And then i suspect some weird string operations..
>I repeat:
> this only happens if $string contains some (one ??) of $chars
>
>Please.. some other explanation ???
>
>--
>pozdrawiam..
>
> ## ## | Sylwester Zarêbski - ISP Group |
> #### ## | e-mail: sylwek@isp.net.pl |
> ## ## ## | ICQ uin: #45780888 |
> ## #### ## | Administrator ISP.NET.PL |
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>