note 74286 deleted from function.strpos by cmb

From: Date: Sun, 02 Jun 2019 09:01:56 +0000
Subject: note 74286 deleted from function.strpos by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211178@lists.php.net to get a copy of this message
Note Submitter: gal_chen123 at hotmail dot co dot il ---- 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.

« previous php.notes (#211178) next »