regex pattern in php to find phone number between plain text -


i trying phone number between plain text. here, facing typical problem. pattern have written not matching types of phone numbers. ex:

$string  = 'sample text sample text sample text (216) 499 1001 sample text sample text (262) 335 60 76-77 sample text sample text sample text'; $string = str_replace('\n', php_eol, $string); //my regex pattern  $regex = '/(?:1(?:[. -])?)?(?:\((?=\d{3}\)))?([2-9]\d{2})(?:(?<=\(\d{3})\))? ?(?:(?<=\d{3})[.-])?([2-9]\d{2})[. -]?(\d{4})(?: (?i:ext)\.? ?(\d{1,5}))?\s+?/';   preg_match_all($regex, $string, $matches); print_r($matches); 

which giving me first phone number , not second one. plz me in getting pattern also.

 output:     array     (         [0] => array             (                 [0] => (216) 499 1001             )  ---- --- 

thanks in advance!

hi write algorithm

1) fetch whole string array 2) start scan document using loop(till end of line) 3) use is_numeric function finding finding numbers , count total digits use if statement (10 digits= phone number, 5 digits=postal code that) 4) if phone number move value in temp array else next line(use space separator) 4)now u can process all

if want filter phone number area code or service provider, u can use following codes

<?php $strings = array('+91', '+11', '+97'); foreach ($strings $testcase) {     if (ctype_digit($testcase)) {         echo "match found .\n";     } else {         echo "not matching.\n";     } } ?> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -