0

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

2
Contributors
7
Replies
11
Views
5 Years
Discussion Span
Last Post by samiyahg
0

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.

0

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!

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

print_r($matches);
0

Thank you blocblue.

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

0

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.. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.