944,103 Members | Top Members by Rank

Ad:
  • PHP Code Snippet
  • Views: 1264
  • PHP RSS
0

Find String in PHP Ready easy function

by on Sep 12th, 2009
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
PHP Code Snippet (Toggle Plain Text)
  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:
Previous Thread in PHP Forum Timeline: Back button problem with $Sessions and GET
Next Thread in PHP Forum Timeline: <?php vs. <?





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


Follow us on Twitter


© 2011 DaniWeb® LLC