Hi, I need help in writing a regular expression accoding to the following criteria:

preg_match (keywords tel/contact/phone/phne/telephone which can be found anywhere in the string) followed by 7 int(numbers).

Thnx,
Regards,
Sami

Recommended Answers

All 7 Replies

Hi Sami, perhaps you could post your code thus far.

Seems you've asked this question before. And the answer remains the same.

If the format and structure of the string from which you want to extract the data isn't consistent, then a regular expression isn't going to work reliably.

for example this is the new string i get when i trim and preg_replace the . / : and space

tel7051636mitsubishilanceryear00fulloptionmoteurdohcinjectionbodykitjantecosmicpourplusdereseignementtel7787425seriousbuyeronlypricers475000chevroletaveols//sep11 6000kmsredfulloptionsmanual

as u can see, i can get the phone number (that is the 7 numbers ) just after the tel
I just want to get that data. Do u have any idea how to do that?

Thank you!

$string = 'tel7051636mitsubishilanceryear00fulloptionmoteurdohcinjectionbodykitjantecosmicpourplusdereseignementtel7787425seriousbuyeronlypricers475000chevroletaveols';
preg_match_all('tel([\d]+)', $string, $matches);

print_r($matches);

Thank you blocblue.

I am getting this error :Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash

I solved it by adding a delimitor #

<?php

  $string = 'tel7051636mitsubishilanceryear00fulloptionmoteurdohcinjectionbodykitjantecosmicpourplusdereseignementtel7787425seriousbuyeronlypricers475000chevroletaveols';
  preg_match_all('#tel[\d]+#', $string, $matches);
  print_r($matches);

?>

output :

Array ( [0] => Array ( [0] => tel7051636 [1] => tel7787425 ) )

Thank you.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.