note 96614 deleted from function.substr by danbrown

From: Date: Mon, 08 Mar 2010 16:18:34 +0000
Subject: note 96614 deleted from function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166782@lists.php.net to get a copy of this message
Note Submitter: Enrico Giancipoli / fr4nk [ at ] aol [ dot ] it ---- <?php //How to get a subtring between a starting string and an ending string $s = "ireallylove2000onion2001chips"; //original sting $string_a = '2000'; //starting string $string_b = '2001'; //ending string $x = strpos($s, "$string_a"); $x = $x + strlen($string_a); $y = strpos($s, "$string_b"); $y = strlen($s) - $y; $z = substr($s, $x, -$y); //returns the substring beetween 2000 and 2001 echo "$z"; //prints onion ?>

« previous php.notes (#166782) next »