943,187 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 433
  • PHP RSS
Jul 2nd, 2010
0

PHP regular expresions HELP!

Expand Post »
I want a partner for preg_split for multiple matches. For example
preg_split('/(.be|.fr|.im|.fi)/i', $input[$i], -1, PREG_SPLIT_DELIM_CAPTURE);
I tried something like this but doesnt work. I want for example to search for these
5 strings and if it finds them split the string there. Anyone know?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
D4n1sD is offline Offline
47 posts
since Feb 2010
Jul 3rd, 2010
0
Re: PHP regular expresions HELP!
What did not work ? Give an example of what you want to happen, and what does happen. Did you get an error ?
Sponsor
Featured Poster
Reputation Points: 546
Solved Threads: 717
Bite my shiny metal ass!
pritaeas is offline Offline
4,143 posts
since Jul 2006
Jul 3rd, 2010
0
Re: PHP regular expresions HELP!
What is happening is the strangest thing ever, the strangest thing I ever had while coding I dunno how to explain it. Here is the source

PHP Syntax (Toggle Plain Text)
  1. $text=$_POST['comments'];
  2. function ValidateEmail($email) {
  3. $valid = true;
  4. $findats = strrpos($email, "@");
  5. if (is_bool($findats) && !$findats) {
  6. $valid = false;
  7. }
  8. else {
  9. $domain = substr($email, $findats+1);
  10. $local = substr($email, 0, $findats);
  11. $locallength = strlen($local);
  12. $domainlength = strlen($domain);
  13. if ($locallength < 1 || $locallength > 64) {
  14. $valid = false;
  15. }
  16. elseif ($domainlength < 1 || $domainlength > 256) {
  17. $valid = false;
  18. }
  19. elseif ($local[0] == '.' || $local[$locallength-1] == '.') {
  20. $valid = false;
  21. }
  22. elseif ((preg_match('/\\.\\./', $local)) || (preg_match('/\\.\\./', $domain))) {
  23. $valid = false;
  24. }
  25. elseif (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
  26. $valid = false;
  27. }
  28. elseif (!preg_match('/^(\\\\.|[A-Za-z0-9_.-])+$/', str_replace("\\\\","",$local))) {
  29. if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) {
  30. $valid = false;
  31. }
  32. }
  33. }
  34. if ($valid) {
  35. return 1;
  36. }
  37. else {
  38. return 0;
  39. }
  40. }
  41.  
  42. function explodeX($delimiters,$string)
  43. {
  44. $return_array = Array($string);
  45. $d_count = 0;
  46. while (isset($delimiters[$d_count]))
  47. {
  48. $new_return_array = Array();
  49. foreach($return_array as $el_to_split)
  50. {
  51. $put_in_new_return_array = explode($delimiters[$d_count],$el_to_split);
  52. foreach($put_in_new_return_array as $substr)
  53. {
  54. $new_return_array[] = $substr;
  55. }
  56. }
  57. $return_array = $new_return_array;
  58. $d_count++;
  59. }
  60. return $return_array;
  61. }
  62.  
  63. $input=explodeX(Array("!"," ","#","$","%","^","&","*","(",")","=","+","{","}","]","[",";",":","'","\\","\"","|",",","/","?","<",">"),$text);
  64.  
  65. $i=0;
  66. while($i<count($input))
  67. {
  68. $final=preg_split('/(.be|.fr|.eu|.com|.me|.net|.org|.info|.biz|.pro|.cc|.tv|.mobi|.tel|.am|.fm|.mu|.nu|.name|.it|.li|.lu|.ch|.nl|.me.uk|.co.uk|.org.uk|.de|.at|.re|.es|.pt|.pl|.cz|.cx|.gs|.tl|.cat|.cn|.tw|.ht|.ie|.us|.lv|.lt|.im|.fi)/', $input[$i], -1, PREG_SPLIT_DELIM_CAPTURE);
  69. $d=0;
  70. while($d<count($final))
  71. {
  72. echo $final[$d]."<br>";
  73. $d=$d+1;
  74. }
  75.  
  76. $i=$i+1;
  77. }


There are some non used variables etc that I used them for some tests etc dont pay attention to them. What I want to do is to search within strings
e-mail adresses and print them. For example u enter adlkasdlak@asdas.com wdawkda@kdasda.com; <dwadawdawdaw@dasdad.com> adawdawdwd@dasdadwaw.comawdwadwdw@dasda.com things like that.
However when I input one single e-mail it works fine but when putting huge strings I
get CRAZIEST outputs ever. Example

jurwloj.1982@lovw.fr jurwloj.1982@lovw.fr To: gjut.jnnw@hotmjol.fr; crys_20@hotmjol.com;    crys_20@hotmjol.com; koffwn-21@hotmjol.fr; mjswbj@cwgwtwl.nwt; wlyjzonj@hotmjol.fr; kjronwmso@hotmjol.fr; lwsgrosswspowrrws@hotmjol.fr; mjrojnnwcjndotto@hotmjol.fr; do-dou89@lovw.fr; nonowg39@hotmjol.fr--* to@gmjol

while inputing this string it will split jurwloj.1982@lovw.fr jurwloj.1982@lovw.fr
into different pieces like ju rw loj.1982@ lo vw .fr while all the next e-mails
will be outputted normally. And some of them might get splited aswell its really confusing. If u have msn plz give to me I might be able to show you.
Reputation Points: 10
Solved Threads: 0
Light Poster
D4n1sD is offline Offline
47 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: sql error
Next Thread in PHP Forum Timeline: PHPMyAdmin - run mysql_fix_privilege_tables script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC