Have an account? Sign in
Login  Register  Facebook
Can any one have a solution to this php problem
Hi Team,
I need to split the below contents by using the mobile number and email id.
If the mobile number and email id found the content is splitted into some blocks.
I am using the preg_match_all to check the mobile number and email id.

For example :
The Given Content:
WANTED B\'ful Non W\'kingEdu Fair Girl for MBA 28/175 H\'some Fair Mangal Gotra Boy Well estd. B\'ness HI Income Status family Email: [email protected] PQM4 h\'some Convent Educated B.techIIT, MS/28/5\'9\" Wkg in US frm repu fmlyseek b\'ful,tall g i r l . Mo:09893029129 Em:[email protected] 5\' 2\" to 5\' 5\" b\'ful QLFD girl for h a n d s o m e 5\' 8\" BPT (I) MPT G.Medalist (AUS) wkg in Australia Physiotherapist boy from V.respectable fmly of Surat / DeUli. Tel: 09825147614. EmaU: [email protected]

The Desired output should be:
  • 1st block:
  • WANTED B\'ful Non W\'kingEdu Fair Girl for MBA 28/175 H\'some Fair Mangal Gotra Boy Well estd. B\'ness HI Income Status family Email: [email protected]
  • 2nd block:
  • PQM4 h\'some Convent Educated B.techIIT, MS/28/5\'9\" Wkg in US frm repu fmlyseek b\'ful,tall g i r l . Mo:09893029129 Em:[email protected]
  • 3rd block:
  • 5\' 2\" to 5\' 5\" b\'ful QLFD girl for h a n d s o m e 5\' 8\" BPT (I) MPT G.Medalist (AUS) wkg in Australia Physiotherapist boy from V.respectable fmly of Surat / DeUli. Tel: 09825147614. EmaU: [email protected]

I do no how to split it.I need some logics.
When i am using preg_match_all when ever a mobile number found i inserted a new line and split the blocks.But email id is splitted independently.


Thank you,
Prem
Started: September 17, 2011 Latest Activity: September 17, 2011 php
2 Answers
All you want to do is insert newlines? Try this:
preg_replace('/.*?\w+@\w+.\w+\s*/', "$0\n\n, $data);

(I used two linefeeds to achieve visual as well as logical separation.)

Posted: xtremex
In: September 17, 2011

Not a real solution, but this will make your work a little easier.
  $str = \"WANTED ...so on... U: [email protected]\";
  $items = preg_split(\"/(?<=\\\\d{11}|\\.com|\\.in)/\", $str);
  echo $str.\"\\n\";
  echo print_r($items);
Look behind assertions need to be of fixed width - otherwise we could have tried for something better. or To split them after emails is not easy due to fixed width look-behind requirement. Splitting before email address is easier:
$items = preg_split(\"/(?<=[\\s:])(?=[\\\\w.+-]+@[\\w.-]+(\\s|$))/\", $str);
Note: Email address matching using regex is not as trivial as it has done here; but given the sample text, I guess this is reasonable.

Posted: MacOS
In: September 17, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer