Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Matthew Carter Newsgroups: comp.lang.php Subject: Re: extract values from string Date: Sat, 14 Nov 2015 23:20:59 -0500 Organization: Ahungry (http://ahungry.com) Lines: 55 Message-ID: <87io53uc44.fsf@ahungry.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="7c986cd4736462de309a749b207746fe"; logging-data="12886"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0FgcisAQTi88fKkROlIGU" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:ZDQgAWjBAqNeE9gXRTfqHCkocb4= sha1:iH1pyE89RD85R/ptSlvWoufW2y4= Xref: csiph.com comp.lang.php:15903 Jerry Stuckle writes: > On 11/14/2015 5:39 AM, albert wrote: >>> After further thinking about this, here's a shorter version which uses >>> explode() twice and might work for you, also: >>> >>> function findvals($str) { >>> $nums = explode('/', $str); >>> if (count($nums) != 3) >>> return false; >>> $vals = explode(" ", $nums[2]); >>> return $vals; >>> } >>> >>> $data = findvals("xx/yy/178 1771 80 279"); >>> if ($data) >>> print_r($data); >>> else >>> echo "Error!\n"; >>> >> >> >> which is more fast? > > Speed is not as important as readability and maintainability. Write > your code so you and others can understand and maintain it. If you have > problems with speed in the future, then determine where the problems lie > and fix those. This is more readable IMHO: