Find String in PHP Ready easy function

meabed meabed is offline Offline Sep 12th, 2009, 10:24 pm |
0
Better way to find String in PHP ! instead of substring and other php function , This function takes Start and End , and it will return the String in between in another variable ! you can call it easily
Quick reply to this message  
PHP Syntax
  1. function findtxt($start,$end,$str,&$var) {
  2. if(stristr($str,$start) && stristr($str,$end)) {
  3. $txt_pos_s = strpos($str,$start) + strlen($start);
  4. $txt_pos_e = strpos($str,$end,$txt_pos_s);
  5. $txt_length = $txt_pos_e - $txt_pos_s;
  6. $txt = substr($str,$txt_pos_s,$txt_length);
  7. $var = $txt;
  8. return TRUE;
  9. }
  10. else {
  11. return FALSE;
  12. }
  13. }
  14.  
  15. //Call the function
  16. $str="Address 1: Cairo 14 Street </br> Address 2: bla bla bla ";
  17. findtxt('Address 1:','Address 2:',$str,$s1);
  18. // then you can remove the html tags from the result string which is $s1
  19. $s1=strip_tags($s1);

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC