note 74286 modified in function.strpos by danbrown

From: Date: Sun, 17 May 2009 16:32:35 +0000
Subject: note 74286 modified in function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154844@lists.php.net to get a copy of this message
this function returns the text between 2 strings: <?php function get_between ($text, $s1, $s2) { $mid_url = ""; $pos_s = strpos($text,$s1); $pos_e = strpos($text,$s2); for ( $i=$pos_s+strlen($s1) ; ( ( $i < ($pos_e)) && $i < strlen($text) ) ; $i++ ) { $mid_url .= $text[$i]; } return $mid_url; } ?> if $s1 or $s2 are not found, $mid_url will be empty to add an offset, simply compare $pos_s to the offset, and only let it continue if the offset is smaller then $pos_s. --was-- this function returns the text between 2 strings: function get_between ($text, $s1, $s2) { $mid_url = ""; $pos_s = strpos($text,$s1); $pos_e = strpos($text,$s2); for ( $i=$pos_s+strlen($s1) ; ( ( $i < ($pos_e)) && $i < strlen($text) ) ; $i++ ) { $mid_url .= $text[$i]; } return $mid_url; } if $s1 or $s2 are not found, $mid_url will be empty to add an offset, simply compare $pos_s to the offset, and only let it continue if the offset is smaller then $pos_s. http://php.net/manual/en/function.strpos.php

« previous php.notes (#154844) next »