FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » strpos() before str_replace()? Or, maybe strtr()?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: strpos() before str_replace()? Or, maybe strtr()? [message #184935 is a reply to message #184927] Sun, 16 February 2014 23:17 Go to previous messageGo to previous message
Norman Peelman is currently offline  Norman Peelman
Messages: 126
Registered: September 2010
Karma:
Senior Member
On 02/16/2014 02:21 PM, Ben Bacarisse wrote:
> Norman Peelman <npeelman(at)cfl(dot)rr(dot)com> writes:
>
>> On 02/16/2014 04:49 AM, Jason C wrote:
> <snip>
>>> foreach ($userArr as $key => $val) {
>>> if (strpos($firstname, $key) !== false)
>>> $firstname = str_replace($key, "****", $firstname);
>>>
>>> if (strpos($lastname, $key) !== false)
>>> $lastname = str_replace($key, "****", $lastname);
>>> }
>>
>>
>> It's slower because you are actually performing the same function
>> twice on each iteration.
>
> Did you try it? In my tests it's faster (37ms vs 66ms). This may be
> because of the assignment always being done.
>
> I am not saying you could not have got different numbers, just that the
> only way to be sure is to test with the real data in the real
> environment.
>

Thanks for pointing that out. I didn't think of it that way.



--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: getting php mail error info
Next Topic: Declaring an array necessary?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 04:14:11 GMT 2024

Total time taken to generate the page: 0.05400 seconds