Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <32394685.JNGdiLLVUf@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Tue, 18 Feb 2014 01:33:18 +0100 User-Agent: KNode/4.11.5 Content-Transfer-Encoding: 7Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <1816957.0LDT0NebiR@PointedEars.de> <0.9da5fd4e321b89e9adc3.20140216202439GMT.877g8u7qm0.fsf@bsb.me.uk> <0.1d3b7c8128d5ae4333af.20140216205119GMT.87siri6at4.fsf@bsb.me.uk> <2051024.CPFVgIA8O1@PointedEars.de> <0.72f969f4ca3b7fcb1715.20140216231324GMT.87ha7y648b.fsf@bsb.me.uk> MIME-Version: 1.0 Lines: 41 NNTP-Posting-Date: 18 Feb 2014 01:33:20 CET NNTP-Posting-Host: 5026b8fd.newsspool1.arcor-online.net X-Trace: DXC=A;a7S[9nea5d8Nb@@ZG@b=ic==]BZ:af>4Fo<]lROoR1nkgeX?EC@@0g^WmZX^PGj3DZm8W4\YJN@[hLNg?m9_lZ649Y;3Y0 X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.php:12862 Ben Bacarisse wrote: > Thomas 'PointedEars' Lahn writes: >> Ben Bacarisse wrote: >>> "J.O. Aho" writes: >>>> On 16/02/14 21:24, Ben Bacarisse wrote: >>>>> Thomas 'PointedEars' Lahn writes: >>>>>> Jason C wrote: >>>>>>> Would it be faster to use strpos() before each str_replace(), like >>>>>>> so?: >>>>>>> >>>>>>> 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); >>>>>>> } >>>>>> >>>>>> Most certainly not. >>>>> >>>>> And yet, when I measured it, it was faster. How can that be? >>>>> >>>>> >>>> >>>> For strpos is faster than str_replace on finding the string. >> >> How, and why? Both search for the occurrence of a substring in a >> string. > > Because strpos has a lower per-call overhead. That is irrelevant regarding the question which function can *find* the string faster, is it not? PointedEars -- Danny Goodman's books are out of date and teach practices that are positively harmful for cross-browser scripting. -- Richard Cornford, cljs, (2004)