|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-03-20 18:27 UTC] nikic@php.net
-Status: Open
+Status: Wont fix
[2016-03-20 18:27 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 00:00:01 2025 UTC |
Description: ------------ 1) It would be much comfortable that array would be indexed with pattern as a string key. $subject = " 12,5 km"; // user can input kilometers, miles, degrees, radians $pattern = '/(km)|(kilometers)|(K)|(miles)|(m)|(degrees)|(deg)|(dg)|(d)|(radians)|(rad)|(rd)|(r)/'; preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE); print_r('<pre>'); print_r($matches); print_r('</pre>'); // returns array([0]=>array([0]=>'km' ,[1]=>'6'), [1]=>array([0]=>'km' ,[1]=>'6') ) It would be much comfortable that array would be indexed with pattern as a string key. In given case it could return instead: array(['km']=>'km' ,[1]=>'6'). This would help to identify not only the search result, but also the property. In this case i would know instantly that user inputs kilometers. 2) It would be much more comfortable that all related information would also be presented as string keys, where 'pos' means position. Thus the first example would return: array(['km']=>'km' ,['pos']=>'6'). And this example would return $pattern = '/(\d+)[,.;](\d+)/'; $subject = " 12,5 km"; preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE); print_r('<pre>'); print_r($matches); print_r('</pre>'); // prints: array([0]=>array([0]=>'12.5' ,[1]=>'1'), [1]=>array([0]=>12 ,[1]=>1), [2]=>array([0]=>5 ,[1]=>4) ) would return instead array( array (['(\d+)[,.;](\d+)']=>'12.5' ,['pos']=>1 ), array (['(\d+)']=> array( ['(\d+)']=>12, ['pos']=>1) ), array( ['(\d+)']=>12, ['pos']=>4) ), ), ) Test script: --------------- $subject = " 12,5 km"; // user can input kilometers, miles, degrees, radians $pattern = '/(km)|(kilometers)|(K)|(miles)|(m)|(degrees)|(deg)|(dg)|(d)|(radians)|(rad)|(rd)|(r)/'; preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE); print_r('<pre>'); print_r($matches); print_r('</pre>'); // returns array([0]=>array([0]=>'km' ,[1]=>'6'), [1]=>array([0]=>'km' ,[1]=>'6') ) $pattern = '/(\d+)[,.;](\d+)/'; $subject = " 12,5 km"; preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE); print_r('<pre>'); print_r($matches); print_r('</pre>'); // prints: array([0]=>array([0]=>'12.5' ,[1]=>'1'), [1]=>array([0]=>12 ,[1]=>1), [2]=>array([0]=>5 ,[1]=>4) )